1. Docs
  2. Quick start

Five-minute path

Run work in order.

Install one package, create one queue, and make each task explicitly release the next.

1 · Install

Add the package.

Node.js 22.13 or newer can consume the runtime through ESM or CommonJS. No compiler, transpiler, or bundler is required.

npm install js-queue

2 · Create

Add functions in FIFO order.

add() validates the complete batch, appends it, and starts the front item when the queue is idle, not stopped, and configured to auto-run.

import Queue from 'js-queue';

const queue=new Queue;

queue.add(
    function(){
        console.log('prepare');
        this.next();
    },
    function(){
        console.log('send');
        this.next();
    },
    function(){
        console.log('record');
        this.next();
    }
);
Use regular functions when you need the queue context.

An arrow function keeps its surrounding this; it does not receive the queue binding.

3 · Release

The task decides when it is done.

js-queue never treats a return value or promise as an automatic completion signal. Call this.next() at the exact release point.

Synchronous

Release inline

queue.add(function(){
    updateCache();
    this.next();
});
Asynchronous

Release in finally

queue.add(function(){
    saveRecord()
        .finally(()=>this.next());
});

Ready for stop gates, error recovery, and real async coordination?

Open patterns