-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (26 loc) · 885 Bytes
/
server.js
File metadata and controls
31 lines (26 loc) · 885 Bytes
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
let express = require('express'),
app = express(),
port = process.env.PORT || 3000,
mongoose = require('mongoose'), //created model loading here
bodyParser = require('body-parser');
// mongoose instance connection url connection
mongoose.connect('mongodb://localhost:27017/todoDB', {
useMongoClient: true
});
mongoose.Promise = global.Promise;
//Adding body parser for handling request and response objects.
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
//Enabling CORS
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
//Initialize app
let initApp = require('./api/app');
initApp(app);
app.listen(port);
console.log('To-do list RESTful API server started on: ' + port);