-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (34 loc) · 1.07 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
/* eslint-disable no-console */
/* eslint-disable no-undef */
// require('dotenv').config();
const express = require('express');
const dotenv = require('dotenv');
const morgan = require('morgan');
// eslint-disable-next-line no-unused-vars
const colors = require('colors');
const errorHandler = require('./middleware/error');
const connectDB = require('./config/db');
// route files
dotenv.config({ path: './config/.env' });
connectDB();
const bootcamps = require('./routes/bootcamps');
const app = express();
// dev logging middleware
// body parser
app.use(express.json());
if (process.env.NODE_ENV === 'development') {
app.use(morgan('dev'));
}
app.use('/api/v1/bootcamps', bootcamps);
app.use(errorHandler);
// eslint-disable-next-line no-undef
const PORT = process.env.PORT || 7890;
const server = app.listen(
PORT,
console.log(`server running on ${process.env.NODE_ENV} mode on ${PORT}`.yellow.bold)
);
process.on('unhandledRejection', (err, promise) => {
console.log(`error: ${err.message}`.red);
server.close(() => process.exit(1));
});
module.exports = app;