Skip to content
Yet Anther Library for Node.js to manage background execution
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
examples
lib
README.md
index.js
package.json

README.md

Backgrounder

Yet another wrapper around the child_process.spawn call supported by Node.js.

There are a lot of other, similar libraries for Node.js out there, that do similar things (as this is a very common problem). This particular one fits my problem set, as it

  • Allows for multiple backrounds works to be created.
  • Uses "require" to manage the code in the sub-modules.
  • Allows users to implement code that is compatible with the child_process.fork call available with v0.5.*.
  • Child processes can use console.log and other console function; the logs are printed by the main process.

Here is exampe for a master:

var util = require("util");
var backgrounder = require("backgrounder");
var worker = backgrounder.spawn("./worker");

worker.on("message", function(message) {
    console.log(util.inspect(message, false, 100));
});

worker.send({
    "title": "hello world!",
    "flag": true
});

This could be the code of the client:

var util = require("util");

console.log('Started the working');

process.on('message', function(message) {
    console.log('Worker received: %s', util.inspect(message, false, 100));

    process.send({
        "received": message
    });
});
Something went wrong with that request. Please try again.