-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (30 loc) · 1.01 KB
/
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
const express = require('express');
const mongoose = require('mongoose');
const bookRoutes = require('./routes/bookRoutes');
require('dotenv').config();
const app = express();
app.use(express.urlencoded({extended:false}));
/** * * * * * * * * * * * * *@ROUTES * * * * * * * * * * * * */
app.use('/api/v1/', bookRoutes);
app.all('*', (req, res)=>{
res.send('404 error! Invalid request')
});
/** * * * * * * * * * * * * *@PORT * * * * * * * * * * * * */
const PORT = 8000 || process.env.PORT;
const startServer = async ()=>{
try{
/** * * * * * * * * * * * * * *@db * * * * * * * * * * * * * */
mongoose.set('strictQuery', false);
await mongoose.connect(process.env.MONGO_URI).then(()=>{
console.log('Connected to db');
}).catch((e)=>{
console.log('Could not connect to db. Error: ' + e);
})
app.listen(PORT, ()=>{
console.log(`The app is running on port ${PORT}`);
});
}catch(e){
console.log(e);
}
}
startServer();