Reputation: 491
It is a very small issue but I can't find out: I have 2 file in the same folder: config.js and server.js. The last one uses the config.js with the following code:
...
var config = ('./config');
...
//Configuration
var port = process.env.PORT || 8080;
mongoose.connect(config.database);
By running the server I have problem with connection due to a wrong address, infact the following error is shown
MongoError: failed to connect to server [undefined:27017] on first connect ...
The config.js contains just:
module.exports = {
'secret' : 'test123',
'database' : 'mongodb://127.0.0.1:27017/test'
};
And If I replace the mongoose.connect with the following code
mongoose.connect('mongodb://127.0.0.1:27017/test');
everything works fine... Why it can't resolve the database name?
Upvotes: 0
Views: 905
Reputation: 569
You must to use var config = require(./config.js)
and config.js must be on the same dir if you do that, the problem is you forgot require
Upvotes: 1