forked from 2pai/codebase-2pai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (23 loc) · 759 Bytes
/
index.js
File metadata and controls
27 lines (23 loc) · 759 Bytes
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
require('dotenv').config();
const cluster = require('cluster');
const server = require('./bin/app/server');
const logger = require('./bin/helper/util/logger');
const cpuCount = require('os').cpus().length;
const mongoDB = require('./bin/infra/databases/mongo/connection');
const Port = process.env.SERVER_PORT || 1337;
const AppServer = new server();
if(cluster.isMaster){
for (let i = 0; i < cpuCount; i += 1) {
cluster.fork();
}
}else{
AppServer.server.listen(Port,() => {
mongoDB.init();
let ctx = 'app-server';
logger.log(ctx,`The server is running on ${Port} workerid = ${cluster.worker.id}`,'init');
});
}
cluster.on('exit', (worker) => {
logger.log('server',`Worker %d died :( ${worker.id}`,'init');
cluster.fork();
});