-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
49 lines (36 loc) · 1.03 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
48
49
'use strict';
// import modules
var express = require('express');
var mongoose = require('mongoose');
var compression = require('compression');
var bodyParser = require('body-parser');
var logger = require('morgan');
var debug = require('debug')('server');
// import custom modules
var routes = require('./routes');
// set up constants
var NODEJS_PORT = parseInt(process.env.NODEJS_PORT) || 4000;
var app = express();
// Log requests
app.use(logger('dev'));
// Add body-parser middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: 'true'}));
// Add response compression middleware
app.use(compression());
// Add the routes to the app
app.use('/', routes());
debug('Added routes');
debug('Added express middleware');
var server;
function startServer() {
server = app.listen(NODEJS_PORT, function() {
debug('Listening on port %d', NODEJS_PORT);
});
}
function closeServer() {
server.close();
}
module.exports.app = app;
module.exports.startServer = startServer;
module.exports.closeServer = closeServer;