Express+mongoDB starts offline, mongodb connection fails, and networking is normal. Has anyone ever encountered this problem?

want to learn nodeJS, learn online tutorials, use express+mongoDB to do a simple blog system, occasionally do not connect to the network to start the project, the result is wrong, can not start normally, when the network connection is normal, everything is normal, when disconnected from the network, offline status, start the project MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: getaddrinfo ENOENT localhost:27017]

error message:

var settings = require("../settings"),
    Db = require("mongodb").Db,
    Connection = require("mongodb").Connection,
    Server = require("mongodb").Server;
module.exports = new Db(settings.db, new Server(settings.host, 27017, {}));

I hope the great god will give me some advice

Mar.01,2021

change localhost to 127.0.0.1


@ enhancer Brother's link is 404, I changed localhost to 127.0.0.1, or did I report an error

< hr >

the problem has been found:
it turns out that I set the setting of the connection mongodb:

  

you can try the node. / bin/www startup project instead of cnpm start startup project.
if you can, please post your package.json file and have a look

Menu