-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
52 lines (41 loc) · 1.09 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
const express = require('express'),
dotenv = require('dotenv'),
morgan = require('morgan'),
colors = require('colors'),
ErrorHandler = require('./middlewares/error');
const connectDB = require('./config/db');
//load env vars
dotenv.config({
path: './config/config.env'
});
const app = express();
//body parser
app.use(express.json());
// connect db
connectDB();
//use morgan
app.use(morgan('dev'));
app.get('/', (req, res) => {
res.status(200).json({
Name: 'Vikashchander'
});
});
// //custom logger
// const logger = require('./middlewares/logger/logger');
// //use custom logger
// app.use(logger);
app.use(ErrorHandler);
const Port = 8000;
//routers
app.use('/api/V1/BootCamp', require('./routes/Api/bootcamp'));
app.use('/api/V1/Courses', require('./routes/Api/courses'));
const server = app.listen(
Port,
console.log(`Server running in at ${Port}`.underline.red)
);
// Handle unhandled promise rejections
process.on('unhandledRejection', (err, promise) => {
console.log(`Error: ${err.message}`.rainbow);
// Close server & exit process
server.close(() => process.exit(1));
});