im getting this error
app.get is not a function
this is my config/express.js
var express = require('express');
module.exports = function(){
var app = express();
app.set('port',3000);
return app;
};
and this is my server.js
var http = require ('http');
var app = require ('./config/express');
http.createServer(app).listen(app.get('port'), function(){
console.log("Express Server Runing on port"+ app.get('port'));
});
what im doing wrong?
im getting this error
app.get is not a function
this is my config/express.js
var express = require('express');
module.exports = function(){
var app = express();
app.set('port',3000);
return app;
};
and this is my server.js
var http = require ('http');
var app = require ('./config/express');
http.createServer(app).listen(app.get('port'), function(){
console.log("Express Server Runing on port"+ app.get('port'));
});
what im doing wrong?
Share Improve this question asked Feb 13, 2017 at 13:30 JohnJohn 5333 gold badges9 silver badges19 bronze badges 1-
are you sure
require ('./config/express')
is the correct path? If you logapp
does it give you something? – Laurens Kling Commented Feb 13, 2017 at 13:33
2 Answers
Reset to default 17in config/express.js
you export a function but use it as an app. Try this instead:
var express = require('express');
var app = express();
app.set('port', 3000);
module.exports = app;
Edit: But the following is preferred:
/* config/express.js */
var express = require('express');
module.exports = function() {
var app = express();
app.set('port', 3000);
return app;
};
/* server.js */
var http = require('http');
var app = require('./config/express')(); // Notice the additional () here
http.createServer(app).listen(app.get('port'), function() {
console.log("Express Server Runing on port"+ app.get('port'));
});
Whenever you use Nodejs and express js or anyother first check your Versions . that can save a lot of time . Like if you move from express 3 to express 4 so you better check versions