-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
63 lines (41 loc) · 1.25 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const express = require('express');
const dotenv = require('dotenv');
const apps = express();
const morgan = require('morgan');
const colors = require('colors');
const connectDB = require('./config/db');
const errorHandler = require('./middlewares/error')
const cookieParser = require('cookie-parser')
// Routes files
const bootcamps = require('./routes/bootcamps.js');
const auth = require('./routes/auth');
const app = express();
//body parser
app.use(express.json())
// Connect env vars
connectDB();
// load env vars
dotenv.config({ path: './config/config.env'});
//body parser
app.use(express.json());
// cookie parser
app.use(cookieParser());
// dev logging middleware
if (process.env.NODE_ENV === 'development') {
use(morgan('dev'));
}
// Mount routers
app.use('/api/v1/bootcamps', bootcamps);
app.use(errorHandler);
app.use('/api/v1/auth', auth);``
const PORT = process.env.PORT || 5000;
app.listen(
PORT, console.log(`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`.yellow.bold))
//Handle unhandled promise rejections
function server(param) {
}
process.on('unhandledRejection', (err, promise) => {
console.log(`Error: ${err.message}`.red);
//close server & exit process
server(() => process.exit(1));
});