Although I tried all suggested solutions in google? But the same error keep popup to me. I checked my mongoDB server and it's work fine. I replaced localhost to 127.0.0.1 and also to 0.0.0.0 but it still not working.
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://127.0.0.1:27017/mydb";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
console.log("Database created!");
db.close();
});