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

@odunlamizo/node-river

v1.1.2

Published

Node.js library to support River integration.

Downloads

1,113

Readme

node-river

Node.js client for River, a Postgres-backed job queue. Supports job insertion and worker-based processing with per-queue concurrency control.

Installation

npm install @odunlamizo/node-river

Setup

import { RiverClient } from '@odunlamizo/node-river';
import { PgDriver } from '@odunlamizo/node-river/drivers/pg';

const driver = new PgDriver({ connectionString: process.env.DATABASE_URL! });

const client = new RiverClient(driver, {
  queues: {
    default: { concurrency: 10 },
    emails: { concurrency: 50 },
  },
  maxAttempts: 3,
});

await client.verifyConnection();

Inserting Jobs

queue is required on every insert — there is no default fallback.

// Single job
const result = await client.insert(
  { kind: 'send_email', to: '[email protected]' },
  { queue: 'emails' },
);
console.log(result.job); // inserted Job record
console.log(result.skipped); // true if deduplicated

// Multiple jobs in one transaction (all succeed or all roll back)
const results = await client.insertMany([
  { args: { kind: 'send_email', to: '[email protected]' }, opts: { queue: 'emails' } },
  { args: { kind: 'send_email', to: '[email protected]' }, opts: { queue: 'emails' } },
]);

// Inside an existing transaction
const tx = await driver.getTx();
try {
  await tx.query('BEGIN');
  await client.insertTx(tx, { kind: 'send_email', to: '[email protected]' }, { queue: 'emails' });
  await tx.query('COMMIT');
} catch (e) {
  await tx.query('ROLLBACK');
  throw e;
} finally {
  tx.release();
}

Unique Jobs

Use uniqueOpts to prevent duplicate jobs from being enqueued.

// Deduplicate by specific args
await client.insert(
  { kind: 'send_email', to: '[email protected]' },
  { queue: 'emails', uniqueOpts: { byArgs: ['to'] } },
);

// Deduplicate by queue + args
await client.insert(
  { kind: 'send_email', to: '[email protected]' },
  { queue: 'emails', uniqueOpts: { byQueue: true, byArgs: ['to'] } },
);

// Deduplicate within a time window (e.g. one per 60-second period)
await client.insert(
  { kind: 'send_email', to: '[email protected]' },
  { queue: 'emails', uniqueOpts: { byPeriod: 60 }, scheduledAt: new Date() },
);

Processing Jobs (Workers)

Implement the Worker<T> interface for each job kind, register it with addWorker, then call work(). Each queue is polled independently at the configured concurrency limit.

import { Job, JobArgs, Worker } from '@odunlamizo/node-river/types';

interface SendEmailArgs extends JobArgs<{ to: string }> {
  kind: 'send_email';
}

class SendEmailWorker implements Worker<SendEmailArgs> {
  async work(job: Job<SendEmailArgs>): Promise<void> {
    await sendEmail(job.args.to);
  }
}

client.addWorker('send_email', new SendEmailWorker());
client.work(); // starts polling all configured queues

Throwing inside work() marks the job as failed. If attempt < maxAttempts it is retried with exponential backoff; otherwise it is discarded.

Shutdown

Always call close() on shutdown to drain the poll timer and release database connections.

process.on('SIGTERM', async () => {
  await client.close();
});

Configuration

| Option | Type | Description | | -------------- | ----------------------------------------- | ------------------------------------------------------------------- | | queues | Record<string, { concurrency: number }> | Queues to poll and their concurrency limits. Required for work(). | | maxAttempts | number | Default max attempts for inserted jobs. | | pollInterval | number | Milliseconds between polls. Defaults to 1000. | | clientId | string | Unique ID for this client instance. Defaults to hostname-pid. |

License

MIT