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

@locallink/client

v0.2.0

Published

Drop-in client for routing database queries through a LocalLink tunnel.

Readme

@locallink/client

Drop-in client for routing database queries through a LocalLink tunnel.

Lets a deployed backend temporarily talk to a local database with minimal code changes — swap one import, add three env vars, done.


How it works

Your deployed backend
        │
        │  POST /r/:resourceId/query  { sql, params }
        ▼
  LocalLink Gateway
        │
        │  socket.io tunnel
        ▼
  Your local machine (locallink CLI running)
        │
        ▼
  Local Postgres DB  →  rows back up the chain

Prerequisites

  1. Register your DB as a resource in the LocalLink dashboard

    • Type: database, engine: postgres, connection string: your local DB URL
    • Note the Resource ID shown after creation
  2. Generate an API key for that resource (dashboard → resource → API Keys tab)

  3. Run the locallink CLI on your local machine so the tunnel is open:

    npx locallink start
    # or if running locally in this repo:
    pnpm --filter @locallink/host dev -- start

Installation

In your backend project:

npm install github:your-org/local-link  # or copy src/pg.ts directly

Or just copy src/pg.ts into your project — it has zero dependencies beyond fetch (Node 18+).


Usage

Pattern 1 — Feature flag via env var (recommended)

No changes to your existing DB code. Add a check at the top of where you create your pool:

import { Pool as PgPool } from 'pg';
import { fromEnv } from '@locallink/client/pg';

// Uses LocalLink tunnel if LOCALLINK_* vars are set, otherwise your real DB.
export const pool = fromEnv() ?? new PgPool({ connectionString: process.env.DATABASE_URL });

Set these env vars when deploying with the tunnel:

LOCALLINK_GATEWAY=https://your-gateway.com
LOCALLINK_RESOURCE_ID=abc123def456        # from the dashboard
LOCALLINK_API_KEY=ll_k_...               # generated in the dashboard

Remove them to go back to your production DB. Zero code changes needed again.

Pattern 2 — Explicit swap

// Before
import { Pool } from 'pg';
const pool = new Pool({ connectionString: process.env.DATABASE_URL });

// After (swap just the import + constructor options)
import { Pool } from '@locallink/client/pg';
const pool = new Pool({
  gateway:    process.env.LOCALLINK_GATEWAY,
  resourceId: process.env.LOCALLINK_RESOURCE_ID,
  apiKey:     process.env.LOCALLINK_API_KEY,
});

// Everything else stays the same
const { rows } = await pool.query('SELECT * FROM users WHERE id = $1', [userId]);

API

new Pool(options)

| Option | Type | Description | |--------------|--------|--------------------------------------------------| | gateway | string | Your gateway URL, e.g. https://gw.example.com | | resourceId | string | Resource ID from the LocalLink dashboard | | apiKey | string | API key generated for this resource |

pool.query(sql, params?)

Same signature as pg.Pool.query. Returns Promise<{ rows, rowCount }>.

const { rows, rowCount } = await pool.query(
  'SELECT * FROM orders WHERE user_id = $1 AND status = $2',
  [userId, 'pending']
);

pool.end()

No-op. Exists so you can swap back to pg.Pool without changing cleanup code.

fromEnv()

Returns a Pool configured from env vars, or null if any are missing. Use this for the feature-flag pattern.


What's supported

| Feature | Supported | |--------------------------|-----------| | SELECT queries | ✅ | | INSERT / UPDATE / DELETE | ✅ | | Parameterized queries | ✅ | | Transactions | ❌ (each query is a separate HTTP round-trip) | | pool.connect() client | ❌ | | Streaming | ❌ |

For transactions, wrap the statements in a single BEGIN ... COMMIT query string if you need them temporarily.


Removing it

  1. Delete the LOCALLINK_* env vars from your deployment
  2. Revert the one-line import change (or remove the fromEnv() check)
  3. Done — back to your real DB