Created
November 24, 2019 16:40
-
-
Save BretCameron/d0b8053a050b9c3fd25cca0b48af02a1 to your computer and use it in GitHub Desktop.
Boilerplate to start an Express server and connect to MongoDB using Mongoose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as express from "express"; | |
import * as mongoose from "mongoose"; | |
const app = express(); | |
const uri = "mongodb://localhost:27017/test"; // replace with your URI | |
mongoose | |
.connect(uri, { | |
useNewUrlParser: true, | |
useCreateIndex: true, | |
useFindAndModify: false, | |
useUnifiedTopology: true | |
}) | |
.then(() => console.log("Connected to MongoDB")) | |
.catch((e: Error) => console.error(e)); | |
const port = 5001; | |
app.listen(port, () => { | |
console.log(`Server started on http://localhost:${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment