Created
April 22, 2021 13:23
-
-
Save syamjayaraj/6296bf9fca61c37898ed84a74d73f5d7 to your computer and use it in GitHub Desktop.
This file contains 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
const express = require("express"); | |
const app = express(); | |
const cors = require("cors"); | |
const bodyParser = require("body-parser"); | |
const logger = require("morgan"); | |
const mongoose = require("mongoose"); | |
mongoose.set("useNewUrlParser", true); | |
mongoose.set("useFindAndModify", false); | |
mongoose.set("useCreateIndex", true); | |
const port = 3031; | |
const config = require("./config"); | |
const postsRouter = require("./routes/posts"); | |
app.use(logger("dev")); | |
const dbUrl = config.dbUrl; | |
var options = { | |
keepAlive: 1, | |
connectTimeoutMS: 30000, | |
useNewUrlParser: true, | |
useUnifiedTopology: true, | |
}; | |
mongoose.connect(dbUrl, options, (err) => { | |
if (err) console.log(err); | |
}); | |
app.use(cors()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.use(bodyParser.json()); | |
app.use("/posts", postsRouter); | |
app.listen(port, function () { | |
console.log("Runnning on " + port); | |
}); | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment