Here's all you have to do to add clustering to your node.js application.
- save this code as
cluster.js, and runcluster.jsinstead ofserver.js(or /bin/www, or whatever it's called for your project) - the only line you'll need to change is the last line - it needs to point to the location of your
server.jsfile
var cluster = require('cluster');
if (cluster.isMaster) {
// Count the machine's CPUs
var cpuCount = require('os').cpus().length;