Answer the question
In order to leave comments, you need to log in
Why won't my NodeJS app connect to MongoDB?
I try to use any manuals, and the result is the same - my "web application" does not connect to the running MongoDB in any way. I execute app.js... And nothing, not a single collection is created, the database does not have a single connection. Execution result: see screenshot, but there seems to be nothing to debug. Help, please?
The app.js code is like this:
// Retrieve
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect("mongodb://localhost:27017/chat", function (err, db) {
if (err) {
return console.dir(err);
}
db.collection('test', function (err, collection) {});
db.collection('test', {
w: 1
}, function (err, collection) {});
db.createCollection('test', function (err, collection) {});
db.createCollection('test', {
w: 1
}, function (err, collection) {});
});
cd E:\Program Files\MongoDB\Server\3.4\bin
mongod.exe --config "E:\Program Files\MongoDB\Cfg\mongod.cfg" --install
net start MongoDB
Answer the question
In order to leave comments, you need to log in
Facepalm guys. I wrote in package.json in a script , but I should have .
Problem solved! "start": "app.js"
"start": "node app.js"
You can also run node app like this
For different versions below, I recommend installing node via nvm
On the server, run via pm2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question