-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrunner.js
More file actions
24 lines (22 loc) · 713 Bytes
/
runner.js
File metadata and controls
24 lines (22 loc) · 713 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
"use strict";
const cluster = require("cluster");
const server = require("./server");
if (cluster.isMaster && process.env.NODE_ENV === "production") {
console.log("Server is active. Forking workers now.");
const cpuCount = require("os").cpus().length;
for (let i = 0; i < cpuCount; i++) {
console.log("Starting worker...");
cluster.fork();
}
cluster.on("exit", worker => {
console.error(`Worker ${worker.id} has died! Creating a new one.`);
cluster.fork();
});
} else {
server.listen(process.env.SERVER_PORT, function() {
console.log(
`${server.name} listening at ${server.url} [worker id: ${cluster.worker
.id}, port: ${process.env.SERVER_PORT}]`
);
});
}