-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
42 lines (34 loc) · 960 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
/**
* Main application file
*/
const express = require('express');
const http = require('http');
// New line
const mongoose = require('mongoose');
const expressConfig = require('./config/express');
const routeConfig = require('./routes');
// New Line
const config = require('./config/environment');
// Connect to MongoDB
mongoose.connect(config.mongo.uri, { useNewUrlParser: true });
mongoose.connection.on('error', (err) => {
console.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.shoppingCartBK = server.listen(config.port, config.ip, () => {
console.log(`Express server listening on ${config.port}, in ${app.get('env')} mode`);
});
}
setImmediate(startServer);
// Expose app
module.exports = app;