App.set('port', Port) 'typeerror: Undefined Is Not A Function'. Beginner, Need Ideas
Solution 1:
You are not exporting anything in the app.js
file. At the end of app.js
file, include following line.
module.exports = app;
See whether your problem goes away.
And one more addition: you have var app = express();
twice in your app.js
.
Solution 2:
You don't have declared any function called set
inside the app.js
file.
Create that function and export it like this:
exports.set = function(...) { ... };
If this app
is the express app
yo especify a port like this:
var express = require('express'),
http = require('http');
var app = express();
http.createServer(app).listen(port);
instead of
app.set('port', port);
/**
* Create HTTP server.
*/var server = http.createServer(app);
This is because the port is a property of the http server and not of the express app
You can use also
var express = require('express'),
app = express();
app.listen(port);
Solution 3:
Intaned of calling export please use module.export end the end of your script.
exports = app;module.exports = app;
Solution 4:
At the bottom of your app.js:
app.set('port', process.env.PORT || 26398); //<--- replace with your port number// Servervar server = http.createServer(app);
server.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
module.exports = app;
Solution 5:
In my case I simply moved the normalizePort function before the function was called. This was in coffeescript but I've converted it to javascript here.
normalizePort = function(val) {
var port;
var port;
port = parseInt(val, 10);
if (isNaN(port)) {
returnval;
}
if (port >= 0) {
return port;
}
returnfalse;
};
port = normalizePort(process.env.PORT || '4000');
Post a Comment for "App.set('port', Port) 'typeerror: Undefined Is Not A Function'. Beginner, Need Ideas"