-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (28 loc) · 897 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
require('dotenv').config();
require('express-async-errors');
const express = require('express');
const app = express();
const notFound = require('./middleware/not-found');
const errorHandlerMiddleware = require('./middleware/error-handler');
const authRouter = require('./routes/auth');
const jobRouter = require('./routes/job')
const connectDB = require('./db/connect')
const authenticateUser = require('./middleware/authenticated')
//middelware
app.use(express.json())
//routers
app.use('/api/auth',authRouter )
app.use('/api/jobs', authenticateUser, jobRouter)
//error handler
app.use(notFound);
app.use(errorHandlerMiddleware);
const port = process.env.PORT || 3000
const start = async () => {
try {
await connectDB(process.env.MONGO_URI)
app.listen(port, console.log(`listening to port${port}`));
} catch (error) {
console.log(error);
}
}
start();