-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
29 lines (26 loc) · 757 Bytes
/
app.js
File metadata and controls
29 lines (26 loc) · 757 Bytes
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
require('dotenv').config();
require('express-async-errors');
const express = require('express');
const connectDB = require('./database/db');
const { auth, courses } = require('./routes/routes');
const ErrorHandler = require('./middlewares/error-handler');
const jwtAuth = require('./middlewares/auth');
const app = express();
//Middlewares
app.use(express.json());
//Routes
app.use('/api/v1/auth', auth);
app.use('/api/v1/courses', jwtAuth, courses);
//Error Handler
app.use(ErrorHandler);
//Start Function
const start = async () => {
try {
connectDB(process.env.MONGO_URI);
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listening on port ${port}`));
} catch (error) {
console.log(error);
}
};
start();