-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
47 lines (37 loc) · 1.29 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// import packages
const express = require('express');
const bodyParser = require('body-parser');
// create express app
const app = express();
// parse request of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
// parse requests of content-type - application/json
app.use(bodyParser.json());
/* DataBase configuration start */
const dbConfig = require('./config/database.config');
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
// Connection the DataBase
mongoose.connect(dbConfig.url, {
useNewUrlParser: true,
})
.then(() => {
console.log('Successfully connected to DataBase');
})
.catch((err) => {
console.log('Could not connect to DataBase. Exiting now...', err);
process.exit();
});
/* DataBase configuration end */
// define a base route
app.get('/', (req, res) => {
res.json({ 'message': "Welcome to EasyNotes application. Take notes quickly. Organize and keep track of all your notes." });
});
// Require Notes routes
require('./app/routes/note.routes.js')(app);
// listen for requests
app.listen(3000, () => {
console.log('================================');
console.log('Server is listening on port 3000');
console.log('================================');
});