Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
168
rated 0 times [  172] [ 4]  / answers: 1 / hits: 23860  / 4 Years ago, fri, may 1, 2020, 12:00:00

I am new to Node js and got some issues. Previously I was using node Js v13.8 to run my express application and it was working very well. I was using es6 syntax and type module having JS extension files. But, when I upgraded to Node 14.1.0. It's showing the following error(Same error with 13.9 as well).



TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension for D:Projectsmatri-sitebinwww.



Here is my error snippet



Again when I downgraded to Node 13.8, it works fine.



Here is my package.json file :





{
name: matri-site,
version: 0.0.0,
private: true,
type: module,
scripts: {
start: node ./bin/www
},
dependencies: {
bcryptjs: ^2.4.3,
buffer: ^5.5.0,
cookie-parser: ~1.4.4,
debug: ~2.6.9,
express: 4.16.1,
handlebars: ^4.7.6,
http-errors: ~1.6.3,
jade: ~1.11.0,
jsonwebtoken: ^8.5.1,
mongoose: ^5.8.9,
morgan: ~1.9.1,
nodemailer: ^6.4.2,
redis: ^3.0.2,
validator: ^12.1.0,
validatorjs: ^3.18.1
},
devDependencies: {
eslint: ^6.8.0
}
}





Here is my WWW file:





#!/usr/bin/env node

/**
* Module dependencies.
*/

// var app = require('../app');
// var debug = require('debug')('matri-site:server');
// var http = require('http');

import app from '../app.js';
import debug from debug;
debug.debug('matri-site:server');
import http from http;

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server error event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server listening event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}




More From » node.js

 Answers
33

Ok I write the solution here if you succeeded, in addition I also tell you the reasons for the error.
WWW needs an extension, like .js (WWW.js). This is because get_format.js tries to get the type of exetension, it's all written in the error generated in the console.


[#50983] Wednesday, April 22, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
draven

Total Points: 641
Total Questions: 101
Total Answers: 110

Location: Nicaragua
Member since Mon, Sep 26, 2022
2 Years ago
;