-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (30 loc) · 820 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
//creating express application
const express = require('express');
const app = express();
// setting logger up
const logger = require('./utils/logger')
//to use .env parameters
const config = require('config');
//adding routes
const routes = require('./api_routes/routes');
routes(app);
//if cors needed
// const cors = require("cors");
// var corsOptions = {
// origin: "http://localhost:8081"
// };
// app.use(cors(corsOptions));
// get MongoDB driver connection
const dbo = require("./db/dbConn");
//starting the server
const port = config.get('port');
// perform a database connection when the server starts
dbo.connectToServer(function (err) {
if (err) {
console.error(err);
process.exit();
}
})
app.listen(port, () => {
logger.info(`Listening to port http://localhost:${port}`);
});