-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
38 lines (28 loc) · 828 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
require('dotenv').config();
const express=require('express');
const bodyparser=require('body-parser');
const mongoose=require('mongoose');
const cors=require('cors');
const app=express();
app.use(cors());
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({extended:true}));
mongoose.Promise=global.Promise;
mongoose.connect(process.env.MONGO_URL,{ useNewUrlParser: true }).then(()=>
{console.log("DB is connected");}
).catch((err)=>{
console.log(err);
process.exit();
})
app.get('/',(req,res)=>{
res.send("Welcome to the class");
});
require('./routes/route')(app);
app.use('*',(req,res,next)=>{
res.status(404).json({"msg":"Not found"});
});
const Port=process.env.PORT||3000;
app.listen(Port,(err)=>{
if(err) console.log(err);
else console.log(`port is live at ${Port}`);
});