Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including microjob with all npm packages installed. Try it out:

var microjob = require("microjob")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

microjob v0.7.0

A tiny wrapper for Node.js worker_threads lib


npm version Build Status Coverage Status Dependencies

A tiny wrapper for turning Node.js threads in easy-to-use routines for CPU-bound.


Microjob is a tiny wrapper for Node.js threads and is intended to perform heavy CPU loads using anonymous functions.

So, Microjob treats Node.js threads as temporary working units: if you need to spawn a long-living thread, then you should use the default API.

From version v0.1.0 microjob uses a Worker Pool 🎉

Microjob follows the same line of the original Node.js documentation: use it only for CPU-bound jobs and not for I/O-bound purposes. Quoting the documentation:

Workers are useful for performing CPU-intensive JavaScript operations; do not use them for I/O, since Node.js’s built-in mechanisms for performing operations asynchronously already treat it more efficiently than Worker threads can.

Microjob can be used only with Node.js 10.5+ and with the --experimental-worker flag activated, otherwise it won't work.

More details explained in: Microjob: a tiny multithreading library for Node.js


Via npm:

$ npm install --save microjob

Quick Example

(async () => {
  const { job, start, stop } = require("microjob");

  try {
    // start the worker pool
    await start();

    // this function will be executed in another thread
    const res = await job(() => {
      let i = 0;
      for (i = 0; i < 1000000; i++) {
        // heavy CPU load ...

      return i;

    console.log(res); // 1000000
  } catch (err) {
  } finally {
    // shutdown worker pool
    await stop();


  • 🛢️ Worker Pool
  • 🏥 auto self-healing
  • 🙌 easy and simple
  • 🕔 supports both sync and async jobs
  • 🛡️ huge test coverage
  • 📜 well documented


Dive deep into the documentation to find more examples: Guide

Known Issues

Known Limitations

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free