-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (32 loc) · 962 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
const express = require('express');
const app = express();
const mongoose = require('mongoose');
require('dotenv/config');
const bodyParser = require('body-parser');
app.use(bodyParser.json());
mongoose.set('bufferCommands', false);
//import Routes
const postsRoute = require('./routes/posts');
app.use('/posts', postsRoute);
//Routes
app.get('/',(req,res)=>{
res.send('Hello world');
});
//middleware
app.use('/post',() => {
console.log("This is the paragraph");;
})
//connect to DB
const m = async ()=>{
try{
const val = await mongoose.connect(process.env.DB_CONNECTION,{ useUnifiedTopology: true , useNewUrlParser: true });
}catch(ex){
console.log(ex.message);
}
}
m().then(console.log("connected"));
// mongoose.connect(process.env.DB_CONNECTION,{ useUnifiedTopology: true , useNewUrlParser: true }, (req,res) =>
// console.log("DB")
// );
//server listing port
app.listen(3000);