What's the difference with childprocess.fork between cluster.fork

node.js

Solution

Read the docs: `child_process.fork` vs `cluster.fork`.

The difference between `cluster.fork()` and `child_process.fork()` is simply that cluster allows TCP servers to be shared between workers. `cluster.fork` is implemented on top of `child_process.fork`.

http://nodejs.org/api/cluster.html

1. can I pass arguments to cluster.fork

Not according to the docs, and:

> var cluster = require('cluster')
undefined
> cluster
{ isWorker: false,
  isMaster: true,
  fork: [Function],
  _startWorker: [Function],
  _getServer: [Function] }
> cluster.fork.length
0

(a function's `length` is its number of formal parameters). Use message passing instead.

2. can I listen on same port or unixsock for ChildProcess create by child_process.fork

Presumably yes, since `cluster.fork` is implemented on top of `child_process.fork`. However, there is a reason that `cluster.fork` already exists, if you want to listen on the same port.

Problem

Simple question: What's the difference with child_process.fork between cluster.fork detail: can I pass arguments to cluster.fork can I listen on same port or unixsock for ChildProcess create by child_process.fork

Original source