-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (34 loc) · 1.15 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
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');
// create express app
var app = express();
app.use(cors());
// parse application/x-www-form-urlencoded
app.use(bodyParser.json({limit: '2mb'}));
app.use(bodyParser.urlencoded({limit: '2mb', extended: true}));
// parse application/json
app.use(bodyParser.json())
// Configuring the database
var dbConfig = require('./config/database.config.js');
var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect(dbConfig.url, {
useMongoClient: true
});
mongoose.connection.on('error', function() {
console.log('Could not connect to the database. Exiting now...');
process.exit();
});
mongoose.connection.once('open', function() {
console.log("Successfully connected to the database");
})
// define a simple route
app.get('/', function(req, res){
res.json({"message": "Welcome to EasyNotes application. Take notes quickly. Organize and keep track of all your notes."});
});
require('./app/routes/node.routes.js')(app);
// listen for requests
app.listen(3000, function(){
console.log("Server is listening on port 3000");
});