-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (32 loc) · 1.2 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
39
40
41
42
43
44
const express = require('express');
const path = require('path');
const cors = require('cors');
const bodyParser = require('body-parser');
const logger = require('morgan');
const mongoose = require('mongoose')
const jwt = require('jsonwebtoken');
const config = require('./config');
const app = express()
app.use(logger('dev'));
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.use((req, res,next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
// load the router
app.use('/',require('./routes/index'))
app.use('/users',require('./routes/users'))
// connect moongodb
mongoose.connect(config.MONGO_DB_URL, {
useNewUrlParser : true,
useUnifiedTopology: true
});
mongoose.connection.on("error", console.log);
mongoose.connection.on("open", function() {
console.log(" >> Connected to MongoDB Server Successfully >> ");
});
app.listen(config.PORT,(err)=>{
console.log(`running at ${config.PORT}`);
});