[](https://www.npmjs.com/package/@netlify/neon) [](LICENSE)
npm install @netlify/neon

Netlify-optimized wrapper for @neondatabase/serverless with automatic environment configuration.
> @neondatabase/serverless is Neon's PostgreSQL driver for JavaScript and TypeScript. It's:
> - Low-latency, thanks to message pipelining and other optimizations
> - Ideal for serverless/edge deployment, using https and WebSockets in place of TCP
> - A drop-in replacement for node-postgres, aka pg (on which it's based)
Automatically uses your Neon database connection via Netlify environment variables:
``bashInstall package
npm install @netlify/neon
Basic Usage
`ts
import { neon } from '@netlify/neon'
const sql = neon() // automatically uses env NETLIFY_DATABASE_URLconst [post] = await sql
SELECT * FROM posts WHERE id = ${postId}
// post is now { id: 12, title: 'My post', ... } (or undefined)
`Usage with
Drizzle-ORM
`ts
// ./src/db/index.ts
import { neon } from '@netlify/neon'
import { drizzle } from 'drizzle-orm/neon-http'
import { posts } from "./schema"export const db = drizzle({
schema,
client: neon() // Uses NETLIFY_DATABASE_URL automatically
})
// ./src/db/schema.ts
import { integer, pgTable, varchar, text } from 'drizzle-orm/pg-core'
export const postsTable = pgTable('posts', {
id: integer().primaryKey().generatedAlwaysAsIdentity(),
title: varchar({ length: 255 }).notNull(),
content: text().notNull().default('')
})
`$3
`ts
import { db } from "./db"
import { postsTable } from "./db/schema"const posts = await db.select().from(postsTable)
`Read more about using Drizzle-ORM with Neon: Get started
With additional options
The neon function imported from @netlify/neon also supports all of the same HTTP options as @neondatabase/serverless.`ts
import { neon } from '@netlify/neon'// automatically using connection string from env NETLIFY_DATABASE_URL
const sql = neon({
arrayMode: true,
fetchOptions: { priority: 'high' }
})
// or when explicitly passing in a connection string override
const sql = neon("postgres://user:pass@host/db",{
arrayMode: true,
fetchOptions: { priority: 'high' }
})
`Transactions
Supports all Neon transaction options:
`ts
import { neon } from '@netlify/neon'const sql = neon() // automatically uses env NETLIFY_DATABASE_URL
const showLatestN = 10
const [posts, tags] = await sql.transaction(
[sql
SELECT FROM posts ORDER BY posted_at DESC LIMIT ${showLatestN}, sqlSELECT FROM tags],
{
isolationLevel: 'RepeatableRead',
readOnly: true,
}
)
``š Neon Serverless Driver Docs
š Drizzle with Neon Postgres