I've been developing a simple web app using MongoDB, Express and NodeJS. As of yesterday, I can't seem to connect to MongoDB and keep getting the following error on the terminal:
(node:28265) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Mon goNetworkError: getaddrinfo ENOTFOUND localhost localhost:27017]
at Pool. (/Users/Mendis/Desktop/UMISC_Website/node_modules/mongodb-core/lib/topologies/server.js:564:11)
at Pool.emit (events.js:182:13) at Connection. (/Users/Mendis/Desktop/UMISC_Website/node_modules/mongodb-core/lib/connection/pool.js:317:12)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at Socket. (/Users/Mendis/Desktop/UMISC_Website/node_modules/mongodb-core/lib/connection/connection.js:246:50)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:28265) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an asy nc function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:28265) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are no t handled will terminate the Node.js process with a non-zero exit code.
Here is a snippet from my app.js file up until the mongoDB connection:
/*=========================package/schema imports=============================*/
var passportLocalMongoose = require("passport-local-mongoose"),
methodOverride = require("method-override"),
localStrategy = require("passport-local"),
bodyParser = require("body-parser"),
nodemailer = require("nodemailer"),
passport = require("passport"),
mongoose = require("mongoose"),
express = require("express"),
seedDB = require("./seeds"),
app = express();
var Event = require("./models/event"),
User = require("./models/user");
/*==================================app config================================*/
// connect to umisc database
mongoose.connect("mongodb://localhost:27017/umisc", {useNewUrlParser: true});
Since I'm fairly new to backend development, I'm really unsure of what I've done wrong...
node app.js
– nugget_boi