MongoDB?! Error 502 - bad gateway



Since 2 days I can’t use MondoDB and Mongoose anymore. This is the error message I get:
(node:12049) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED]

Error 502 - Bad Gateway

This is the code that should give me access:

var mongoose = require(“mongoose”);
mongoose.Promise = global.Promise;
mongoose.connect(‘mongodb://localhost/auth_demo_app’, {
useMongoClient: true,

Thank you


Assuming you followed the guide here, you’ll have created a mongod file. If not, follow the instructions to create it. Then, run ./mongod in a new terminal to start MongoDB. In a different terminal, run your code, and it should connect to the database.