Nodejs is built to run on a single process, but you can spawn other processes. The cluster module uses the fork method from the child_process module, but it's intended for distributing connections of a server across processes and sharing the same port.
I think you want exec. Example:
var exec = require('child_process').exec,
child;
var array = ["a", "b", "c", "d", "e"]; // your array of data
var n = array.length; // length
var done = 0; // jobs done
var i = n; // iterator
while(i--) { // reverse while loops are faster
(function (argument) { // A closure
child = exec('node otherFunction.js '+argument, // Spawn the process, with an item from your array as an argument.
function (error, stdout, stderr) {
if (error === null) {
done += 1;
if (done === n) {
console.log('Everything is done');
}
}
});
})(array[i]);
}
The above is of course bad code and not even tested, but I think it would work. All you have to do is call the function you wanted to call on the array's items in otherFunction.js
, inside that you would find the arguments in process.argv
.