Nodejs

Views as a Service for Hack Club Challenges

fork
loading
Files
  • index.js
  • app.js
  • package-lock.json
index.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
const cluster = require("cluster");
const os = require("os");
const startApp = require("./app");

const respawn = worker => {
    console.log(`W${worker.id}: Process exited, respawning`);
    worker.disconnect();
    cluster.fork();
};

if(cluster.isMaster) {
    console.log(`M${process.pid}: Master running`);
    const workerCount = os.cpus().length;
    for(let i = 0; i < workerCount; i++) {
        cluster.fork();
    }
    cluster.on("error", respawn);
    cluster.on("exit", respawn);
}
else {
    startApp();
}

process.on("uncaughtException", e => {
    console.log(e);
});
node v10.16.0