connect event (net.Socket)

Event: 'connect' Emitted when a socket connection is successfully established. See connect().

cluster.worker

cluster.worker <Object> A reference to the current worker object. Not available in the master process. const cluster = require('cluster'); if (cluster.isMaster) { console.log('I am master'); cluster.fork(); cluster.fork(); } else if (cluster.isWorker) { console.log(`I am worker #${cluster.worker.id}`); }

cluster.settings

cluster.settings <Object> execArgv <Array> list of string arguments passed to the Node.js executable. (Default=process.execArgv) exec <String> file path to worker file. (Default=process.argv[1]) args <Array> string arguments passed to worker. (Default=process.argv.slice(2)) silent <Boolean> whether or not to send output to parent's stdio. (Default=false) uid <Number> Sets the user identity of the process. (See setuid(2).) gid <Number> Sets the gr

cluster.setupMaster()

cluster.setupMaster([settings]) settings <Object> exec <String> file path to worker file. (Default=process.argv[1]) args <Array> string arguments passed to worker. (Default=process.argv.slice(2)) silent <Boolean> whether or not to send output to parent's stdio. (Default=false) setupMaster is used to change the default 'fork' behavior. Once called, the settings will be present in cluster.settings. Note that: any settings changes only affect future calls to .fork()

cluster.workers

cluster.workers <Object> A hash that stores the active worker objects, keyed by id field. Makes it easy to loop through all the workers. It is only available in the master process. A worker is removed from cluster.workers after the worker has disconnected and exited. The order between these two events cannot be determined in advance. However, it is guaranteed that the removal from the cluster.workers list happens before last 'disconnect' or 'exit' event is emitted. // Go through all w

cluster.schedulingPolicy

cluster.schedulingPolicy The scheduling policy, either cluster.SCHED_RR for round-robin or cluster.SCHED_NONE to leave it to the operating system. This is a global setting and effectively frozen once you spawn the first worker or call cluster.setupMaster(), whatever comes first. SCHED_RR is the default on all operating systems except Windows. Windows will change to SCHED_RR once libuv is able to effectively distribute IOCP handles without incurring a large performance hit. cluster.schedulingP

cluster.isWorker

cluster.isWorker <Boolean> True if the process is not a master (it is the negation of cluster.isMaster).

cluster.isMaster

cluster.isMaster <Boolean> True if the process is a master. This is determined by the process.env.NODE_UNIQUE_ID. If process.env.NODE_UNIQUE_ID is undefined, then isMaster is true.

cluster.fork()

cluster.fork([env]) env <Object> Key/value pairs to add to worker process environment. return <cluster.Worker> Spawn a new worker process. This can only be called from the master process.

cluster.disconnect()

cluster.disconnect([callback]) callback <Function> called when all workers are disconnected and handles are closed Calls .disconnect() on each worker in cluster.workers. When they are disconnected all internal handles will be closed, allowing the master process to die gracefully if no other event is waiting. The method takes an optional callback argument which will be called when finished. This can only be called from the master process.