Skip to content

Instantly share code, notes, and snippets.

@cnorthwood
Created February 17, 2022 21:50
Show Gist options
  • Save cnorthwood/9026d224988a486035a7081fbdc032f4 to your computer and use it in GitHub Desktop.
Save cnorthwood/9026d224988a486035a7081fbdc032f4 to your computer and use it in GitHub Desktop.
using cluster module for multiple CPUs
import cluster from "cluster";
import { cpus } from "os";
import app from "./app";
const numWorkers = cpus().length;
if (cluster.isPrimary) {
for (let i = 0; i < numWorkers; i++) {
cluster.fork();
}
} else {
app.listen(8443);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment