-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (31 loc) · 863 Bytes
/
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
var config = require('./config');
// middlewares and express.
var express = require('express'),
bodyparser = require('body-parser'),
logger = require('morgan');
// MongoDB integration.
var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect(config.dbpath, function (err) {
if (err) throw err;
});
// Import Models.
var models = {
records: require('./models/records')(mongoose)
};
// Import Routers.
var records = require('./routers/records')(models.records);
var app = express();
//implement middleware.
app.use(logger('dev'));
app.use(bodyparser.json({limit: 10000}));
app.use('/records', records);
// Error Handler.
app.use(function(req, res) {
res.status(404);
res.send("Route not found!");
});
// start the app.
app.listen(config.PORT, function () {
console.log('listening on port: ' + config.PORT);
});