-
Notifications
You must be signed in to change notification settings - Fork 9
/
server.js
33 lines (25 loc) · 913 Bytes
/
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
// Import the packages
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
// Create an instance for express
const app = express();
// Get the person routes
const person = require('./routes/person');
// Apply the bodyParser middleware, to get json data from requests (Body)
app.use(bodyParser.json());
// Apply the routes of /api/person
app.use('/api/person', person);
// Get the mongoURI for database
const db = require('./config/keys').mongoURI;
// Connecting with database
mongoose
.connect(db, { useNewUrlParser: true })
// If all run ok, console log the message
.then(() => console.log('MongoDB connected'))
// For console log any error
.catch(err => console.log(err));
// Port declaration
const port = process.env.PORT || 9000;
// Init the express.js server
app.listen(port, () => console.log(`Server running on ${port}`));