forked from binitghetiya/express-sequelize-api-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (26 loc) · 844 Bytes
/
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
require('@babel/register');
const cluster = require('cluster');
const app = require('./app');
if (cluster.isMaster && process.env.NODE_ENV === 'production') {
const numWorkers = require('os').cpus().length;
console.log(`Master cluster setting up ${numWorkers} workers...`);
for (let i = 0; i < numWorkers; i += 1) {
cluster.fork();
}
cluster.on('online', (worker) => {
console.log(`Worker ${worker.process.pid} is online`);
});
cluster.on('exit', (worker, code, signal) => {
console.log(
`Worker ${
worker.process.pid
} died with code: ${code}, and signal: ${signal}`,
);
console.log('Starting a new worker');
cluster.fork();
});
} else {
app.listen(process.env.APP_PORT || 3000, () => {
console.log(`Process ${process.pid} is listening to all incoming requests`);
});
}