Skip to content

Instantly share code, notes, and snippets.

@dante-byte
Created March 26, 2020 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dante-byte/1aa3c8e04e2a46abc9a4a0f3eeb5aeea to your computer and use it in GitHub Desktop.
Save dante-byte/1aa3c8e04e2a46abc9a4a0f3eeb5aeea to your computer and use it in GitHub Desktop.
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 127.0.0.1:27017
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 https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (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