npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsjob

v0.10.13

Published

Run arbitrary JavaScript as jobs in a browser sandbox

Downloads

35

Readme

Build Status

JsJob

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.

License

MIT

Status

In production

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

Roadmap

2.x

  • 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!

Installing

Get it from NPM

npm install --save jsjob

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

http://phantomjs.org/download.html

Alternatively, get PhantomJS 1.x from NPM

npm install --save phantomjs

Examples

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

Usage

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>

Options:

  -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

Developing

Get the code

git clone [email protected]: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