Skip to content

Instantly share code, notes, and snippets.

@syamjayaraj

syamjayaraj/index.js

Created Apr 22, 2021
Embed
What would you like to do?
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