forked from PasinduS96/location-api-sl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (37 loc) · 1.11 KB
/
index.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
46
47
48
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const cors = require('cors');
const cities = require('./src/routes/city');
const districts = require('./src/routes/district');
const provinces = require('./src/routes/province');
require("dotenv").config();
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json());
app.use(express.static('public'))
app.use(cors())
app.set('view engine', 'ejs')
app.listen(process.env.PORT, () =>{
console.log(`server started at ${process.env.PORT}`);
//Connect to the database
mongoose.Promise = global.Promise;
mongoose
.connect(process.env.MONGO_URI,{
useFindAndModify: false,
useNewUrlParser: true,
useUnifiedTopology: true
}, (err, db) =>{
if(!err){
console.log("MongoDB Connected Successfully!!")
}else{
console.log(err);
}
})
})
app.get('/', (req,res) => {
res.render('index')
})
app.use('/cities', cities)
app.use('/districts', districts)
app.use('/provinces', provinces)