-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·56 lines (44 loc) · 1.2 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
50
51
52
53
54
55
56
'use strict';
/**
* Module dependencies.
*/
var init = require('./config/init')(),
config = require('./config/config'),
mongoose = require('mongoose'),
_ = require('lodash'),
chalk = require('chalk');
// Dependencies for Cluster
var cluster = require('cluster');
var os = require('os');
var throng = require('throng');
/**
* Main application entry file.
* Please note that the order of loading is important.
*/
// Bootstrap db connection
var db = mongoose.connect(config.db, function(err) {
if (err) {
console.error(chalk.red('Could not connect to MongoDB!'));
console.log(chalk.red(err));
}
});
// Init the express application
var app = require('./config/express')(db);
// Bootstrap passport config
require('./config/passport')();
// // Start the app by listening on <port>
// app.listen(config.port);
// Start the app by listening on <port> after forking cluster
var cpus = os.cpus().length;
var workers = process.env.WEB_CONCURRENCY || cpus;
var start = function(){
app.listen(config.port);
};
throng(start, {
workers: workers,
lifetime: Infinity
});
// Expose app
exports = module.exports = app;
// Logging initialization
console.log('Application started on port ' + config.port);