-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
37 lines (26 loc) · 980 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
const express = require('express');
const dotenv = require('dotenv');
const logger = require('./middleware/logger');
const connectDB = require('./config/db');
const colors = require('colors');
/* Load ENV variables */
dotenv.config ( { path:'./config/config.env' } );
/* Coonect to Mongoose database*/
connectDB();
/* Routers Files */
const bootcamp = require('./routes/bootcamp');
const app = express();
/* Body Parser Middleware*/
app.use(express.json());
/* Custom Middleware */
app.use(logger);
/* Mount Routers*/
app.use('/api/v1/bootcamps', bootcamp);
const PORT = process.env.PORT || 5000
const server = app.listen( PORT, console.log (`Server is running in ${ process.env.NODE_ENV } mode on port ${ PORT }.`.yellow.bold) );
/* Global Handle Unhandled Promise Rejection*/
process.on('unhandledRejection', (err, Promise) => {
console.log(`Error:${err.message}`.red);
/* Close server and Exit process*/
server.close( () =>{ process.exit(1) } );
});