-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (30 loc) · 976 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
'use strict';
require('dotenv').config();
const logger = require('./util/logger');
const config = require('config');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const express = require('express');
const app = express();
// express server setup
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
const env = process.env.NODE_ENV;
// logging HTTP request in development only
if (env === 'development') {
const morgan = require('morgan');
app.use(morgan('dev'));
} else require('./startup/prod')(app);
// express routes setup
require('./startup/routes')(app);
// set the port
const port = process.env.PORT || config.get('PORT');
// log startup message
const { name } = require('../package.json');
const server = app.listen(port, () => {
logger.info(`app booted on ${env} environment`);
logger.info(`${name} is listening on ${port}`);
});
module.exports = server;