Skip to main content

Query Neon PostgreSQL from serverless/worker/edge functions over WebSockets or https

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
70%
Published
3 weeks ago (1.0.1)
class neonConfig
extends EventEmitter

Properties

writeonly
coalesceWrites: NeonConfig["coalesceWrites"]
writeonly
disableSNI: NeonConfig["disableSNI"]
writeonly
disableWarningInBrowsers: NeonConfig["disableWarningInBrowsers"]
writeonly
forceDisablePgSSL: NeonConfig["forceDisablePgSSL"]
writeonly
pipelineConnect: NeonConfig["pipelineConnect"]
writeonly
pipelineTLS: NeonConfig["pipelineTLS"]
writeonly
rootCerts: NeonConfig["rootCerts"]
writeonly
subtls: NeonConfig["subtls"]
writeonly
useSecureWebSocket: NeonConfig["useSecureWebSocket"]
writeonly
webSocketConstructor: NeonConfig["webSocketConstructor"]
readonly
webSocketConstructor: NeonConfig["webSocketConstructor"]
writeonly
wsProxy: NeonConfig["wsProxy"]
readonly
coalesceWrites: NeonConfig["coalesceWrites"]
readonly
disableSNI: NeonConfig["disableSNI"]
readonly
disableWarningInBrowsers: NeonConfig["disableWarningInBrowsers"]
readonly
forceDisablePgSSL: NeonConfig["forceDisablePgSSL"]
readonly
pipelineConnect: NeonConfig["pipelineConnect"]
readonly
pipelineTLS: NeonConfig["pipelineTLS"]
readonly
rootCerts: NeonConfig["rootCerts"]
readonly
subtls: NeonConfig["subtls"]
readonly
useSecureWebSocket: NeonConfig["useSecureWebSocket"]
readonly
wsProxy: NeonConfig["wsProxy"]

Methods

connect(
port: number | string,
host: string,
connectListener?: () => void,
): void
destroy(): this
end(
data?: Buffer | string,
encoding?: string,
callback?: () => void,
): this
rawWrite(data: Uint8Array): void
ref(): this
setNoDelay(): this
startTls(host: string): Promise<void>
unref(): this
write(
data: Buffer | string,
encoding?: string,
callback?: (err?: any) => void,
): boolean

Static Properties

writeonly
coalesceWrites: NeonConfig["coalesceWrites"]
writeonly
disableSNI: NeonConfig["disableSNI"]
writeonly
disableWarningInBrowsers: NeonConfig["disableWarningInBrowsers"]
writeonly
fetchConnectionCache: NeonConfig["fetchConnectionCache"]
writeonly
fetchEndpoint: NeonConfig["fetchEndpoint"]
writeonly
fetchFunction: NeonConfig["fetchFunction"]
writeonly
forceDisablePgSSL: NeonConfig["forceDisablePgSSL"]
opts: Partial<NeonConfig>
writeonly
pipelineConnect: NeonConfig["pipelineConnect"]
writeonly
pipelineTLS: NeonConfig["pipelineTLS"]
writeonly
poolQueryViaFetch: NeonConfig["poolQueryViaFetch"]
writeonly
rootCerts: NeonConfig["rootCerts"]
writeonly
subtls: NeonConfig["subtls"]
writeonly
useSecureWebSocket: NeonConfig["useSecureWebSocket"]
writeonly
webSocketConstructor: NeonConfig["webSocketConstructor"]
writeonly
wsProxy: NeonConfig["wsProxy"]
readonly
coalesceWrites: NeonConfig["coalesceWrites"]

Batch multiple network writes per run-loop into a single outgoing WebSocket message.

Default: true.

readonly
disableSNI: NeonConfig["disableSNI"]

When using subtls with forceDisablePgSSL = false and Postgres connection parameters that specify TLS, setting disableSNI = true means that no SNI data in included in the Postgres TLS handshake.

On Neon, disabling SNI and including the Neon project name in the password avoids CPU-intensive SCRAM authentication, but this is only relevant for earlier iterations of Neon's WebSocket support.

Default: false.

readonly
disableWarningInBrowsers: NeonConfig["disableWarningInBrowsers"]

When disableWarningInBrowsers is set to true, it disables the warning about running this driver in the browser.

Default: false.

readonly
fetchConnectionCache: NeonConfig["fetchConnectionCache"]

DEPRECATED. Previously, only when fetchConnectionCache was true did queries carried via HTTP fetch make use of a connection pool/cache on the server. All queries now use the connection pool/cache: this setting is ignored.

Default: true.

readonly
fetchEndpoint: NeonConfig["fetchEndpoint"]

Set fetchEndpoint to set the server endpoint to be sent queries via http fetch. May be useful in local development (e.g. to set a port that's not the default 443).

Provide either the full endpoint URL, or a function that takes the database host address, port and options, and returns the full endpoint URL (including protocol).

Default: custom logic to connect to Neon endpoints.

readonly
fetchFunction: NeonConfig["fetchFunction"]

The fetchFunction option allows you to supply an alternative function for making http requests. The function must accept the same arguments as native fetch.

Default: undefined.

readonly
forceDisablePgSSL: NeonConfig["forceDisablePgSSL"]

Disable TLS encryption in the Postgres protocol (as set via e.g. ?sslmode=require in the connection string). Connection remains secure as long as useSecureWebSocket is true, which is the default.

Default: true

readonly
pipelineConnect: NeonConfig["pipelineConnect"]

Pipelines the startup message, cleartext password message and first query when set to "password". This works only for cleartext password auth.

Default: "password".

readonly
pipelineTLS: NeonConfig["pipelineTLS"]

Pipeline the pg SSL request and TLS handshake when forceDisablePgSSL is false and the Postgres connection parameters specify TLS. Currently compatible only with Neon hosts.

Default: false.

readonly
poolQueryViaFetch: NeonConfig["poolQueryViaFetch"]

Experimentally, when poolQueryViaFetch is true, and no listeners for the "connect", "acquire", "release" or "remove" events are set on the Pool, queries via Pool.query() will be sent by low-latency HTTP fetch request.

Default: false.

readonly
rootCerts: NeonConfig["rootCerts"]

Set rootCerts to a string comprising one or more PEM files. These are the trusted root certificates for a TLS connection to Postgres when forceDisablePgSSL is false and the Postgres connection parameters specify TLS.

Default: "".

readonly
subtls: NeonConfig["subtls"]

If forceDisablePgSSL is false and the Postgres connection parameters specify TLS, you must supply the subtls TLS library to this option:

import { neonConfig } from '@neondatabase/serverless';
import * as subtls from 'subtls';
neonConfig.subtls = subtls;

Default: undefined.

readonly
useSecureWebSocket: NeonConfig["useSecureWebSocket"]

Use a secure (wss:) connection to the WebSocket proxy.

Default: true.

readonly
webSocketConstructor: NeonConfig["webSocketConstructor"]

Only if no global WebSocket object is available, such as in older versions of Node, set webSocketConstructor to the constructor for a custom WebSocket implementation, such as those provided by ws or undici.

Default: undefined.

readonly
wsProxy: NeonConfig["wsProxy"]

Set wsProxy to use your own WebSocket proxy server.

Provide either the proxy server’s domain name, or a function that takes the database host and port and returns the proxy server address (without protocol).

Example: (host, port) => "myproxy.example.net?address=" + host + ":" + port

Default: host => host + '/v2'

Add Package

deno add jsr:@neon/serverless

Import symbol

import { neonConfig } from "@neon/serverless";
or

Import directly with a jsr specifier

import { neonConfig } from "jsr:@neon/serverless";

Add Package

pnpm i jsr:@neon/serverless
or (using pnpm 10.8 or older)
pnpm dlx jsr add @neon/serverless

Import symbol

import { neonConfig } from "@neon/serverless";

Add Package

yarn add jsr:@neon/serverless
or (using Yarn 4.8 or older)
yarn dlx jsr add @neon/serverless

Import symbol

import { neonConfig } from "@neon/serverless";

Add Package

vlt install jsr:@neon/serverless

Import symbol

import { neonConfig } from "@neon/serverless";

Add Package

npx jsr add @neon/serverless

Import symbol

import { neonConfig } from "@neon/serverless";

Add Package

bunx jsr add @neon/serverless

Import symbol

import { neonConfig } from "@neon/serverless";