-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
44 lines (38 loc) · 1.05 KB
/
app.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
/**
* Created by ahhsan on 9/3/16.
*/
/**
* Adding Dependencies
*/
var express = require('express'),
mongoose = require('mongoose'),
bodyParser = require('body-parser');
/**
* Initializing db "databaseName". If don't exist, will create a new one automatically
*/
var db = mongoose.connect('mongodb://localhost/databaseName');
var app = express();
var port = process.env.PORT || 3000;
/**
* Initializing JSON body parsers which read json request data in the form of model fields
*/
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
/**
* Initializing all models here
*/
var Book = require('./src/models/bookModel');
var Person = require('./src/models/personModel');
/**
* Initializing all routers here
*/
bookRouter = require('./src/Routes/bookRoutes')(Book);
personRouter = require('./src/Routes/personRoutes')(Person);
app.use('/api/books', bookRouter);
app.use('/api/persons', personRouter);
/**
* Starting the server on specific port
*/
app.listen(port, function () {
console.log("Running on Port: "+ port);
})