-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (33 loc) · 1016 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
34
35
36
37
38
39
40
41
42
43
44
45
// import packages
require('dotenv').config();
require('express-async-errors');
const express = require('express');
const cookieParser = require('cookie-parser');
// create app express instance
const app = express();
// import db connection function
const connectDB = require('./db/connect');
// import middleware
const { errorHandlerMiddleware } = require('./middleware');
// use middleware
app.use(cookieParser(process.env.COOKIE_SECRET));
app.use(express.json());
// import routes
const authRouter = require('./routes/auth-routes');
const userRouter = require('./routes/user-routes');
// set up routes
const apiRoot = '/api/v1/';
app.get('/', (req, res) => {
res.send('lmao');
});
app.use(apiRoot + 'auth', authRouter);
app.use(apiRoot + 'users', userRouter);
app.use(errorHandlerMiddleware);
const port = process.env.PORT || 5000;
const start = async () => {
await connectDB(process.env.MONGO_URL);
app.listen(port, () => {
console.log(`App is running on port: ${port}`);
});
};
start();