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

@neondatabase/postgrest-js

v0.2.0-beta

Published

PostgreSQL client for Neon Data API - query your database without authentication

Downloads

103,783

Readme

@neondatabase/postgrest-js

npm version npm downloads TypeScript License

Generic PostgreSQL client for Neon Data API without built-in authentication.

Overview

@neondatabase/postgrest-js provides a lightweight PostgreSQL client for querying Neon databases without requiring Neon Auth integration. It's ideal for scenarios where:

  • Authentication is handled externally (e.g., API keys, custom auth providers)
  • You want to bring your own token management
  • You need a minimal client without auth dependencies

For auth-integrated clients, use @neondatabase/neon-js instead.

Installation

npm install @neondatabase/postgrest-js
# or
bun add @neondatabase/postgrest-js

Usage

Basic Client

import { NeonPostgrestClient } from '@neondatabase/postgrest-js';

const client = new NeonPostgrestClient({
  dataApiUrl: 'https://ep-xxx.apirest.region.aws.neon.build/dbname/rest/v1',
  options: {
    global: {
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
      },
    },
    db: {
      schema: 'public',
    },
  },
});

// Query your database
const { data, error } = await client
  .from('users')
  .select('*')
  .eq('status', 'active');

With Token Provider

Use fetchWithToken() for dynamic token resolution:

import { NeonPostgrestClient, fetchWithToken } from '@neondatabase/postgrest-js';

// Your token provider function
const getToken = async () => {
  // Fetch from your auth system, environment, etc.
  return process.env.DATABASE_TOKEN;
};

const client = new NeonPostgrestClient({
  dataApiUrl: 'https://ep-xxx.apirest.region.aws.neon.build/dbname/rest/v1',
  options: {
    global: {
      fetch: fetchWithToken(getToken),
    },
  },
});

// Automatically injects token on every request
const { data } = await client.from('posts').select();

Custom Fetch Implementation

import { NeonPostgrestClient, fetchWithToken } from '@neondatabase/postgrest-js';

const customFetch: typeof fetch = async (input, init) => {
  console.log('Making request:', input);
  return fetch(input, init);
};

const client = new NeonPostgrestClient({
  dataApiUrl: 'https://ep-xxx.apirest.region.aws.neon.build/dbname/rest/v1',
  options: {
    global: {
      fetch: fetchWithToken(getToken, customFetch),
    },
  },
});

API Reference

NeonPostgrestClient

Extends the upstream PostgrestClient with Neon-specific configuration.

Constructor Options:

type NeonPostgrestClientConstructorOptions<SchemaName> = {
  dataApiUrl: string;
  options?: {
    db?: {
      schema?: SchemaName; // Database schema (default: 'public')
    };
    global?: {
      fetch?: typeof fetch; // Custom fetch implementation
      headers?: Record<string, string>; // Global headers
    };
  };
};

Example:

const client = new NeonPostgrestClient({
  dataApiUrl: 'https://your-api-url.com/rest/v1',
  options: {
    db: { schema: 'public' },
    global: {
      headers: { 'X-Custom-Header': 'value' },
    },
  },
});

fetchWithToken()

Generic fetch wrapper that injects authentication tokens.

Signature:

function fetchWithToken(
  getAccessToken: () => Promise<string | null>,
  customFetch?: typeof fetch
): typeof fetch

Parameters:

  • getAccessToken: Async function that returns the current access token
  • customFetch: Optional custom fetch implementation (default: global fetch)

Returns: Wrapped fetch function that automatically adds Authorization: Bearer <token> header

Throws: AuthRequiredError if getAccessToken() returns null

Example:

const authFetch = fetchWithToken(async () => {
  return await getTokenFromYourAuthSystem();
});

// Use with client
const client = new NeonPostgrestClient({
  dataApiUrl: 'https://api.example.com',
  options: { global: { fetch: authFetch } },
});

AuthRequiredError

Error thrown when a request requires authentication but no token is available.

class AuthRequiredError extends Error {
  constructor(message?: string);
}

Usage:

import { AuthRequiredError } from '@neondatabase/postgrest-js';

try {
  await client.from('users').select();
} catch (error) {
  if (error instanceof AuthRequiredError) {
    console.error('Authentication required');
  }
}

Querying

All PostgrestClient query methods are available:

// SELECT
const { data } = await client
  .from('users')
  .select('id, name, email')
  .eq('status', 'active')
  .order('created_at', { ascending: false })
  .limit(10);

// INSERT
const { data } = await client
  .from('users')
  .insert({ name: 'Alice', email: '[email protected]' })
  .select();

// UPDATE
const { data } = await client
  .from('users')
  .update({ status: 'inactive' })
  .eq('id', 123);

// DELETE
const { data } = await client
  .from('users')
  .delete()
  .eq('id', 123);

// RPC (stored procedures)
const { data } = await client
  .rpc('get_user_stats', { user_id: 123 });

Environment Compatibility

Works in both browser and Node.js environments:

  • Browser: Full fetch API support
  • Node.js: Works with Node.js 18+ native fetch or polyfills

TypeScript

Full TypeScript support with generic database types:

interface Database {
  public: {
    users: {
      Row: { id: number; name: string; email: string };
      Insert: { name: string; email: string };
      Update: { name?: string; email?: string };
    };
  };
}

const client = new NeonPostgrestClient<Database>({
  dataApiUrl: 'https://api.example.com',
});

// Fully typed!
const { data } = await client.from('users').select();

Related Packages

Support

License

Apache-2.0