Run arbitrary JavaScript as jobs in a browser sandbox
Last updated 3 years ago by jonnor .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install jsjob 
SYNC missed versions from official npm registry.

Build Status


Greenkeeper badge

Run arbitrary JavaScript code as jobs, in a browser-based sandbox.

Especially designed for medium to large-sized computations with no or limited access to external services, which does not need to syncronize with other computations. Persistence of data is handled outside the job itself. This architecture makes for services which are easy to distribute and scale.

Usecases include

  • Having 'plugins' for a backend/service with well-defined interface and isolation. Independent deploys and faster change-around times, without having to build a microservice. Possibility of allowing 3rd-party extensions.
  • Peer-to-peer distributed processing, across both servers and browsers.
  • Sandboxed execution of native (C/C++ etc) code, by compiling to JS via Emscripten or similar.
  • Building compute-heavy services, including backend, in a frontend/browser-first manner.




In production

  • PhantomJS 2.0 (recommended) and PhantomJS 1.x supported
  • Code used in production at The Grid since March 2015



  • Support for SlimerJS/Gecko and WebDriver
  • WebWorker and client-side runner support

Related projects

  • noflo-jsjob makes it easy to use JsJob in NoFlo applications, and create distributed workers over AMQP/RabbitMQ or MQTT when combined with noflo-msgflo.
  • jsjob-ethereum is an experiement for a decentralized computation market using the Ethereum blockchain.
  • ... Let us know about your project, and we'll link it here!


Get it from NPM

npm install --save jsjob

Install PhantomJS 2.x (recommended), either from upstream or using your OS package manager.


Alternatively, get PhantomJS 1.x from NPM

npm install --save phantomjs


Sudoku solver

Solver code | JsJob plugin | Input format

echo '{"board":".94...13..............76..2.8..1.....32.........2...6.....5.4.......8..7..63.4..8"}' | jsjob-run https://flowhub.github.io/jsjob/examples/sudoku.js


Implement a JsJob plugin

A JsJob needs to implement a single function, window.jsJobRun:

window.jsJobRun = function(inputdata, options, callback) {
  var err = null;
  var result = {'hello': 'jsjob'};
  var details = {'meta': 'data'}; // Can be used for information about the execution or results
  return callback(err, result, details);

This should be bundled into a self-contained (no external dependencies) .js bundle. For non-trivial code, we recommend using NPM modules for dependencies, and building with Webpack or Browserify.

Serve the .js file from a HTTP file-server, which the runner has access to. Locally you can use simple-server from NPM. For publically accessible URL, you can use Github Pages, Amazon S3 or similar.

When deploying to a public server, use SSL/HTTPS!

Run programatically

var jsjob = require('jsjob');

var options = {};
var runner = new jsjob.Runner(options);
runner.start(function(err) {

  var pluginUrl = 'https://example.net/myjsjob.js'; // Something implementing JsJob API
  var inputData = {'bar': "baz"};
  var jobOptions = {};
  runner.runJob(pluginUrl, inputData, jobOptions, function(err, result, details) {
    console.log('jsjob returned', err, result, details);

    runner.stop(function(err) { }); // one can have many runJob() calls for a single runner

Run as script

Basic example

echo '{"input": "sss"}' | jsjob-run http:/localhost:8001/spec/fixtures/jsjobs/return-input.js

Will execute the .js file in browser sandbox with the given data, and then writes result (or error) to the console.

{"input": "sss"}

Supported options

Usage: jsjob-run [options] <job.js>


  -h, --help           output usage information
  --port <portnumber>  Port to use for Runner HTTP server
  --timeout <seconds>  Number of seconds to limit job to
  --verbose [enable]   Verbose, logs console of job execution
  --joboptions <json>  Options to provide the job, as second argument of jsJobRun()
  --script <code>      JavaScript code injected before jsjob.js. Used for polyfills or API adapters

For an up-to-date list, use jsjob-run --help


Get the code

git clone git@github.com:flowhub/jsjob.git

Run the tests

npm test

File an issue

Check the existing list first.

Make a pull request

Fork and submit on Github

Make a release

# change version in package.json
git tag 1.x.y
git push origin HEAD:master --tags
# wait for Travis CI to do the rest

Current Tags

  • 0.10.13                                ...           latest (3 years ago)

14 Versions

  • 0.10.13                                ...           3 years ago
  • 0.10.12                                ...           3 years ago
  • 0.10.11                                ...           4 years ago
  • 0.10.10                                ...           4 years ago
  • 0.10.9                                ...           4 years ago
  • 0.10.8                                ...           4 years ago
  • 0.10.7                                ...           4 years ago
  • 0.10.6                                ...           4 years ago
  • 0.10.5                                ...           4 years ago
  • 0.10.3                                ...           4 years ago
  • 0.10.2                                ...           4 years ago
  • 0.10.0                                ...           4 years ago
  • 0.9.0                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
Maintainers (2)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (4)
Dev Dependencies (14)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |