-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (35 loc) · 1.02 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
/**
* @author Maria Fernanda Serna
* Main application file
*/
const express = require('express');
const mongoose = require('mongoose');
const config = require('./config/environment');
const http = require('http');
const winston = require('winston');
const expressConfig = require('./config/express');
const routeConfig = require('./routes');
mongoose.Promise = require('bluebird');
// Connect to MongoDB
mongoose.connect(config.mongo.uri, config.mongo.options);
mongoose.connection.on('error', (err) => {
winston.error('Error', 'MongoDB connection error', {
data: err,
time: new Date().toISOString(),
});
process.exit(-1);
});
// Setup server
const app = express();
const server = http.createServer(app);
expressConfig(app);
routeConfig(app);
// Start server
function startServer() {
app.angularFullstack = server.listen(config.port, config.ip, () => {
winston.info(`Express server listening on ${config.port}, in ${app.get('env')} mode`);
});
}
setImmediate(startServer);
// Expose app
module.exports = app;