Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
const express = require("express");
app = express();
const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017//fooapp_db", {
useNewUrlParser: true,
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true
const db = mongoose.connection;
db.once("open", () => {
console.log("mongoose started successfully");
app.get("/", (req, res) => {
res.send("hello world express")
app.set("port", process.env.PORT || 3000)
app.listen(app.get("port"), () => {
console.log(`server started on port ${app.get("port")}` )
MacBook-Pro:yoo-app Donta$ node app.js
server started on port 3000
(node:1462) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED
at new MongooseServerSelectionError (/Users/Donta/node_modules/mongoose/lib/error/serverSelection.js:22:11)
at NativeConnection.Connection.openUri (/Users/Donta/node_modules/mongoose/lib/connection.js:823:32)
at Mongoose.connect (/Users/Donta/node_modules/mongoose/lib/index.js:333:15)
at Object.<anonymous> (/Users/Donta/vscode/sandbox/test/test-sandbox/yoo-app/app.js:4:10)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
(node:1462) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see (rejection id: 1)
(node:1462) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment