-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (34 loc) · 939 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require("dotenv").config();
const config = require("config")
const express = require("express")
const morgan = require("morgan")
const cors = require("cors")
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const routes = require("./routes/routes")
const PORT = process.env.PORT ||3000;
const MONGO_CONNECTION = config.get("db.connection-string")
const app = express()
//middlewares
app.use(cors());
app.use(morgan("dev"));
app.use(express.static("public"))
app.use(bodyParser.urlencoded({extended: true}))
app.use("/", routes);
const server = async() => {
try{
await mongoose.connect(MONGO_CONNECTION,{
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true
})
app.listen(PORT, () => {
console.log("Server started on ",PORT)
})
}
catch(e){
console.log(e)
}
};
server();