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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zebranorth/async-beanstalk

v1.0.12

Published

Fast asynchronous Beanstalk client

Readme

Async Beanstalk

GitHub | NPM | Zebra North


About

Async-Beanstalk is a fast, lightweight client for Beanstalk servers.

  • Easy to use
  • Async/await, promise based interface
  • No dependencies
  • Fully asynchronous
  • 10x faster than node-beanstalk
  • Implements the full Beanstalk 1.13 protocol
  • Fully TypeScript safe

Installation with NPM / Yarn

# NPM
npm install @zebranorth/async-beanstalk

# Yarn
yarn add @zebranorth/async-beanstalk

API Documentation

Read the API Documentation here.

Simple Usage

This shows the simplest way to use the client, running each command synchronously.

import { Client } from '@zebranorth/async-beanstalk';

/**
 * A "producer" places jobs into a queue.
 */
async function producer() {
    // Create the client.
    const client = new Client();

    // Connect to the Beanstalk server.
    await client.connect('beanstalk');

    // Set the tube (named queue) into which jobs will be placed.
    await client.use('example-queue');

    // Create an example job.
    const exampleJob = {
        myData: 'This object will be placed into the queue.'
    };

    // Serialize the job into a string and put it into the "example-queue" tube.
    // You can use any serialization. JSON.stringify is convenient.
    await client.put(JSON.stringify(exampleJob));

    // Disconnect from the server.
    await client.close();
}

/**
 * A "consumer" waits for a job to be placed into the queue,
 * then takes it and processes it.
 */
async function consumer() {
    // Create the client.
    const client = new Client();

    // Connect to the Beanstalk server.
    await client.connect('beanstalk');

    // Set the tube from which jobs will be retrieved.
    await client.watch('example-queue');

    // Read the job from the "example" tube.
    const job = await client.reserve();

    console.log('Reserved job ID: ', job.id);
    console.log('Reserved job data: ', JSON.parse(job.payload));

    // Delete the job once it has been successfully processed.
    await client.delete(job.id);

    // Disconnect from the server.
    await client.close();
}

producer();
consumer();

Efficient Bulk Commands

The client contains an internal queue of commands, meaning that you do not have to wait for one command to finish before issuing the next command. Commands are guaranteed to be excuted in the order in which they are issued.

We can take advantage of this by issuing many commands at once, and only waiting for them to complete once we need to close the connection.

import { Client } from '@zebranorth/async-beanstalk';

/**
 * A "producer" places jobs into a queue.
 */
async function producer() {
    // Create the client.
    const client = new Client();

    // Connect to the Beanstalk server.
    await client.connect('beanstalk');

    // Set the tube (named queue) into which jobs will be placed.
    client.use('example-queue');

    // Store promises for commands that have been sent to the server.
    const putCommands: Promise<number>[] = [];

    // Put 100 jobs into the queue.
    for (let i = 0; i < 100; ++i) {
        putCommands.push(client.put('Job ' + i.toString()));
    }

    // Wait for all the jobs to be put into the queue.
    await Promise.all(putCommands);

    // Disconnect from the server.
    await client.close();
}

/**
 * A "consumer" waits for a job to be placed into the queue,
 * then takes it and processes it.
 */
async function consumer() {
    // Create the client.
    const client = new Client();

    // Connect to the Beanstalk server.
    await client.connect('beanstalk');

    // Set the tube from which jobs will be retrieved.
    await client.watch('example-queue');

    // Store promises for commands that have been sent to the server.
    const reserveCommands: Promise<void>[] = []
    const deleteCommands: Promise<void>[] = [];

    // Take 100 jobs from the queue, then delete them.
    for (let i = 0; i < 100; ++i) {
        const reserveJob = client.reserve().then((job) => {
            console.log('Reserved: ' + job.payload);
            deleteCommands.push(client.delete(job.id));
        });

        reserveCommands.push(reserveJob);
    }

    // Wait for all the "reserve" commands to complete.
    await Promise.all(reserveCommands);

    // Wait for all the "delete" commands to complete.
    await Promise.all(deleteCommands);

    // Disconnect from the server.
    await client.close();
}

producer();
consumer();

TypeScript Types

There are some helper types exported.

import { Client, type Job, type Yaml } from '@zebranorth/async-beanstalk';

Job

A Job is returned by reserve() or reserveWithTimeout() and contains two properties: The job ID and the payload as a string.

type Job = {
    /**
     * The Beanstalk server's ID for the job.
     */
    id: number,

    /**
     * The raw job data.
     */
    payload: string
};

Yaml

The Yaml type is an alias for a Map containing numbers or strings, and is used to return server statistics.

type Yaml = Map<string, string | number>;