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

sofa-surfer

v0.3.0

Published

A little API for accessing CouchDB

Readme

Sofa Surfer

A lightweight CouchDB client for Node.js and Deno.

Background

I've written this library many times for different projects and decided to just publish a version I can reuse.

Installation

npm install sofa-surfer

Usage

sofa-surfer exposes a SofaSurfer class. I wanted this to be a plain object, but TypeScript wasn't happy with that. I blame .NET. Anyway.

Pass a connection string including credentials, host, port, and database name:

import { SofaSurfer } from 'sofa-surfer';

// e.g. COUCHDB_URL=http://user:password@localhost:5984/mydb
const db = new SofaSurfer(process.env.COUCHDB_URL);
const doc = await db.get('my-document-id');

API

SofaSurfer

new SofaSurfer(connectionString)

The connection string should be a full URL with credentials, host, port, and database name:

http://username:password@localhost:5984/mydb

Credentials are stripped from the URL before any requests are made, so you won't accidentally leak them into logs.

.get(id)

Fetches a single document by id. Throws CouchDBNotFoundError if it doesn't exist.

const doc = await db.get('my-document-id');

.insert(doc)

Creates a new document. Optionally include _id to specify the document id — otherwise CouchDB will generate one for you.

const result = await db.insert({ name: 'Alice', type: 'user' });
const result = await db.insert({
	_id: 'user-alice',
	name: 'Alice',
	type: 'user',
});

Don't include _rev — that's what .replace() is for. If you try, it'll throw.

.replace(id, rev, doc)

Replaces an existing document. You must provide the current _rev or CouchDB will reject it with a conflict. This is CouchDB's way of keeping you honest.

const result = await db.replace('user-alice', '1-abc123', {
	name: 'Alice',
	type: 'user',
});

.remove(id, rev)

Deletes a document.

const result = await db.remove('user-alice', '2-def456');

.query(viewQuery)

Runs a view query. See ViewQuery below.

const { rows } = await db.query(query);

ViewQuery

sofa-surfer also exposes a ViewQuery class for running CouchDB map-reduce view queries. It's much nicer to use than joining strings.

import { SofaSurfer, ViewQuery } from 'sofa-surfer';

const db = new SofaSurfer(process.env.COUCHDB_URL);

const query = new ViewQuery('design-doc-name', 'view-name').key(
	'my-emitted-key',
);
const { rows } = await db.query(query);

ViewQuery methods return this so calls can be chained to your heart's content:

const today = getCurrentDate();

const query = new ViewQuery('design-doc-name', 'view-name')
	.range([today], [today, {}])
	.update(ViewQuery.UPDATE_AFTER)
	.includeDocs()
	.limit(10);

const { rows } = await db.query(query);

Querying by key

new ViewQuery('ddoc', 'view').key('my-key');
new ViewQuery('ddoc', 'view').keys(['key-one', 'key-two']);

Querying by range

// Exclude end key (default)
new ViewQuery('ddoc', 'view').range('aaa', 'zzz');

// Include end key
new ViewQuery('ddoc', 'view').range('aaa', 'zzz', ViewQuery.INCLUDE_END);

// Compound keys
new ViewQuery('ddoc', 'view').range(['2024'], ['2024', {}]);

// With document id subkeys for pagination
new ViewQuery('ddoc', 'view')
	.range(['2024'], ['2024', {}])
	.idRange('first-doc-id', 'last-doc-id');

Pagination

new ViewQuery('ddoc', 'view').skip(20).limit(10);

Sorting

new ViewQuery('ddoc', 'view').order(ViewQuery.DESCENDING);
new ViewQuery('ddoc', 'view').order(ViewQuery.ASCENDING);

Including documents

new ViewQuery('ddoc', 'view').includeDocs();

Reduce and grouping

new ViewQuery('ddoc', 'view').reduce(); // run reduce
new ViewQuery('ddoc', 'view').reduce(false); // skip reduce
new ViewQuery('ddoc', 'view').group(); // group all
new ViewQuery('ddoc', 'view').group(1); // group_level=1
new ViewQuery('ddoc', 'view').group(false); // disable grouping

Index freshness

// Update index before returning (default)
new ViewQuery('ddoc', 'view').update(ViewQuery.UPDATE_BEFORE);

// Return stale data, update index afterward
new ViewQuery('ddoc', 'view').update(ViewQuery.UPDATE_AFTER);

// Return stale data, do not update index. Living dangerously.
new ViewQuery('ddoc', 'view').update(ViewQuery.UPDATE_NONE);