Reputation: 363
I'm a begginer in NodeJS and when i run node MainApp.js
in console I get this error:
C:\Assigment 2 (NodeJS)\node_modules\mongodb\lib\server.js:235
process.nextTick(function() { throw err; })
^
Error: getaddrinfo ENOTFOUND . .:27017
at errnoException (dns.js:26:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)
I don't know what this means. Inside MainApp I connect mongoose: mongoose.connect("./DataBase");
where DataBase is the folder where I run mongod --dbpath "C:\[...]\DataBase
. The database server seems to start successfully, the console printing: [...] waiting for connections on port 27017
.
server.js lines 231-236:
// Try to callback
try {
callback(err);
} catch(err) {
process.nextTick(function() { throw err; })
}
Package versions: "express": "~4.13.1", "mongodb": "~2.1.0", "mongoose": "~4.3.1"
Upvotes: 2
Views: 4764
Reputation: 1
I changed connection string from mongodb://localhost:27017/ to mongodb://127.0.0.1:27017/ and it worked.
Upvotes: 0
Reputation: 86
make sure that your database is up and running. Go to your terminal and in your app directory run:
mongod
Then restart your node server and you should be good go
Upvotes: 3
Reputation: 363
I do not understand the whole process yet, but I hope this answer will provide some insight:
It seems that running node
or npm start
without starting up the database returns this error.
If database is started, then changing
mongoose.connect("./DataBase");
(which previously caused the error)
to mongoose.connect('mongodb://localhost/database');
fixes the issue.
Intuitively this seems to simply be the error MongoDB returns when it can't find the database used by the server, however this might not be the precise description of the issue.
If someone can provide further insight into the problem, such help would be appreciated.
Upvotes: 2