I
I
Innokenty Ivanov2017-04-04 17:18:48
JavaScript
Innokenty Ivanov, 2017-04-04 17:18:48

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) {});
});

Screenshot with guichette: 25dee85e5793468c9c19a2ed18040577.png
Machine specs:
Type : PC
OS : Windows 10 Anniversary Update
Firewall : Disabled
Using : Visual Studio Code, MongoDB latest versions
Launch MongoDB using bat file from Desktop:
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

2 answer(s)
I
Innokenty Ivanov, 2017-04-05
@Kenya-West

Facepalm guys. I wrote in package.json in a script , but I should have . Problem solved! "start": "app.js""start": "node app.js"

A
Alexander N++, 2017-10-23
@sanchezzzhak

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 question

Ask a Question

731 491 924 answers to any question