-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
33 lines (27 loc) · 833 Bytes
/
app.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
const express = require('express');
const dontenv = require('dotenv');
const morgan = require('morgan');
const coursesRouter = require('./routes/courses');
const studentRouter = require('./routes/students');
const connectDB = require('./config/db');
const errorHandler = require('./middleware/error');
dontenv.config({ path: './config/config.env' });
//initial the app
const app = express();
const PORT = process.env.PORT || 3000;
//connect databse
connectDB();
//MIDDLEWARES
//using the morgan middleware
if (process.env.NODE_ENV === 'development') {
app.use(morgan('dev'));
}
app.use(express.json());
//error handle
//moubt the routes
app.use('/api/v1/courses', coursesRouter);
app.use('/api/v1/students', studentRouter);
app.use(errorHandler);
app.listen(PORT, () => {
console.log(`The server is listing on ${PORT}`);
});