-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
45 lines (37 loc) · 1.16 KB
/
server.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 router = express.Router();
const app = express();
const handlebars = require('express-handlebars');
const mongoose = require('mongoose');
const ObjectID = require('mongodb').ObjectID;
let userModel = require('./models/users');
const bodyParser = require('body-parser');
const cors = require('cors');
const userRouter = require('./routes/user_router');
const PORT = 3000;
const URI = "mongodb+srv://heads:heads@cluster0-v6kuo.mongodb.net/test?retryWrites=true&w=majority"
//middle ware
app.set(cors());
app.set('view engine','ejs');
app.use(bodyParser.urlencoded({
extended: false
}))
app.use(bodyParser.json());
app.use(express.json());
app.use(express.urlencoded());
//database connection
mongoose.connect(URI,{useNewUrlParser:true,useUnifiedTopology:true});
let connection = mongoose.connection;
connection.once('open',() => {
console.log('db connection established');
})
mongoose.set('useFindAndModify',false);
//routes
app.get('/',(req,res)=>{
res.render('index');
})
app.use('/users',userRouter);
//listener
app.listen(PORT,()=>{
console.log('listing on port 3000');
})