-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (30 loc) · 1 KB
/
server.js
File metadata and controls
41 lines (30 loc) · 1 KB
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
const express = require('express');
const bodyParser = require('body-parser'); //used for json parsing.
const mongoose = require('mongoose');
// create express app
const app = express();
// parse requests of content-type - applicaton/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended: true}));
/**
*
* Article - https://www.callicoder.com/node-js-express-mongodb-restful-crud-api-tutorial/
*/
/**************** DB config *******************/
const dbConfig = require('./config/database.config');
mongoose.connect(dbConfig.url, {
useNewUrlParser: true
})
.then(() => {
console.log("Successfully connected to database");
})
.catch(err => {
console.log('Could not connect to the database. Exiting now', err);
process.exit();
});
// parse requests of content-type - application/json
app.use(bodyParser.json());
require('./app/routes/place.route.js')(app);
// listen for requests
app.listen(3000, () => {
console.log("Server is listening on port 3000");
});