-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (35 loc) · 898 Bytes
/
index.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
41
42
43
44
45
46
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const morgan = require("morgan");
const cors = require("cors");
const helmet = require("helmet");
//import config
const config = require("./config");
//import router
const Router = require("./router");
//create app using express
const app = express();
//Connect to the MongoDB
mongoose.connect(config.MONGO_URI, {
user: config.MONGO_USER,
pass: config.MONGO_PASS
})
//Secure Express Apps
app.use(helmet())
//CORS Options
const corsOptions = {
origin: true,
credentials: true
};
app.use(cors(corsOptions));
//Parse the body request to json
app.use(bodyParser.json());
//HTTP request logger with Morgan
app.use(morgan("dev"));
//Router
Router(app);
//Listen server to the specific PORT
app.listen(config.PORT, () => {
console.log(`listen port ${config.PORT}`)
})