Prisma is an open-source ORM for Node.js and TypeScript. This guide shows you how to connect a Prisma application to Neon using the recommended setup with the Neon serverless driver adapter.
Prerequisites
- A Neon account and project
- Node.js 20.19+, 22.12+, or 24+ installed (required by Prisma ORM 7)
- A Node.js or TypeScript project (or create a new one)
Setup
Step 1: Install dependencies
npm install @prisma/client@7 @prisma/adapter-neon@7 dotenv
npm install prisma@7 tsx --save-devnote
This guide uses Prisma ORM 7. Install the prisma CLI, @prisma/client, and @prisma/adapter-neon at the same major version (@7). The prisma package's latest npm tag currently points to a Prisma 8 prerelease, so an unpinned npm install prisma installs a CLI that doesn't match the rest of this setup. If the Prisma CLI later prints an "Update available" notice for Prisma 8, ignore it for this guide.
Step 2: Get your connection strings
From your Neon Console, click Connect and copy both connection strings:
- Pooled connection (has
-poolerin the hostname): for your application - Direct (unpooled) connection: for Prisma CLI commands (migrations, introspection)

Add them to your .env file:
# Pooled connection for your application
DATABASE_URL="postgresql://[user]:[password]@[endpoint]-pooler.[region].aws.neon.tech/[dbname]?sslmode=require&channel_binding=require"
# Direct (unpooled) connection for Prisma CLI
DATABASE_URL_UNPOOLED="postgresql://[user]:[password]@[endpoint].[region].aws.neon.tech/[dbname]?sslmode=require&channel_binding=require"tip
The pooled connection has -pooler in the hostname. The direct (unpooled) connection does not. Both are available in your Neon Console. If you only have the pooled string, remove -pooler from the hostname to get the direct one.
Step 3: Configure your Prisma schema
If you don't have a Prisma schema yet, run npx prisma init to create one. Then update prisma/schema.prisma:
generator client {
provider = "prisma-client-js"
output = "../src/generated/prisma"
}
datasource db {
provider = "postgresql"
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
createdAt DateTime @default(now())
}note
In Prisma 7+, do not include a url property in the datasource block. The connection is configured in the Prisma config file (Step 4) and the adapter.
Step 4: Configure the Prisma CLI connection
The Prisma CLI reads its connection from a config file in your project root. If you ran npx prisma init, it already created one: prisma7.config.ts in Prisma 7.10 and later, or prisma.config.ts in earlier 7.x releases. Replace that file's contents with the following. If you don't have a config file yet, create prisma.config.ts:
import 'dotenv/config'
import { defineConfig, env } from 'prisma/config'
export default defineConfig({
schema: 'prisma/schema.prisma',
datasource: {
url: env('DATABASE_URL_UNPOOLED'),
},
})warning
Keep only one Prisma config file. If both prisma7.config.ts and prisma.config.ts exist, the CLI loads prisma7.config.ts and ignores the other, so CLI commands can end up on the pooled connection. The first line of npx prisma db push output shows which file was loaded (Loaded Prisma config from ...).
Step 5: Create your Prisma Client
Create a file to instantiate Prisma Client with the Neon adapter (for example, src/db.ts):
import 'dotenv/config'
import { PrismaClient } from './generated/prisma'
import { PrismaNeon } from '@prisma/adapter-neon'
const adapter = new PrismaNeon({
connectionString: process.env.DATABASE_URL!,
})
export const prisma = new PrismaClient({ adapter })Step 6: Generate client and push schema
npx prisma generate
npx prisma db pushYou're connected. You can now use Prisma Client in your application:
import { prisma } from './db'
const users = await prisma.user.findMany()To verify the full setup, create a src/main.ts script that exercises CRUD operations:
import { prisma } from './db'
async function main() {
// CREATE
const newUser = await prisma.user.create({
data: { name: 'Alice', email: `alice-${Date.now()}@example.com` },
})
console.log('Created user:', newUser)
// READ
const foundUser = await prisma.user.findUnique({ where: { id: newUser.id } })
console.log('Found user:', foundUser)
// UPDATE
const updatedUser = await prisma.user.update({
where: { id: newUser.id },
data: { name: 'Alice Smith' },
})
console.log('Updated user:', updatedUser)
// DELETE
await prisma.user.delete({ where: { id: newUser.id } })
console.log('Deleted user.')
}
main()
.catch((error) => {
console.error(error)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})Run it with:
npx tsx src/main.tsWhy two connection strings?
Neon uses connection pooling to manage database connections in serverless environments:
- Pooled connection (
DATABASE_URL): Your application connects through Neon's connection pooler, which suits serverless functions that create many short-lived connections. - Direct (unpooled) connection (
DATABASE_URL_UNPOOLED): Prisma CLI commands likeprisma migrateandprisma db pushneed a direct connection for schema operations.
Advanced configuration
Using a non-public Postgres schema
If you're using a Postgres schema other than public, pass a schema option when creating the adapter:
const adapter = new PrismaNeon(
{ connectionString: process.env.DATABASE_URL! },
{ schema: 'myPostgresSchema' }
)Setting the search path for raw SQL queries
For raw SQL queries that reference tables without schema qualification, use the Postgres options parameter in your connection string:
postgresql://[user]:[password]@[neon_hostname]/[dbname]?options=-c%20search_path%3DmyschemanameThis works only on the direct (unpooled) connection. The pooler rejects search_path in startup options, so with the pooled DATABASE_URL, use the adapter's schema option or schema-qualified table names instead.
Troubleshooting
Connection timeouts
If you see an error like:
Error: P1001: Can't reach database server at `ep-example-123456.us-east-2.aws.neon.tech`:`5432`This usually means the connection timed out before Neon activated the compute. Neon computes scale to zero after inactivity and take a few seconds to wake up.
Add a connect_timeout parameter to your connection string:
DATABASE_URL="postgresql://...?sslmode=require&connect_timeout=15"A value of 0 means no timeout.
Connection pool timeouts
With the Neon adapter, the connection pool belongs to the Neon serverless driver, not Prisma. In Prisma 7, the connection_limit and pool_timeout URL parameters have no effect. Pass pool options to the adapter instead:
const adapter = new PrismaNeon({
connectionString: process.env.DATABASE_URL!,
max: 20, // maximum connections in the pool
connectionTimeoutMillis: 15_000, // how long to wait for a connection
})See Prisma's connection pool guide for details.
Using Prisma 6 or earlier
In Prisma 6 and earlier, you configure the connection directly in schema.prisma instead of a Prisma config file:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DATABASE_URL_UNPOOLED")
}The directUrl property is available in Prisma 4.10.0 and higher.
Next steps
- Schema migrations with Prisma: Full tutorial for building an app with migrations
- Neon serverless driver: Learn more about the driver powering the adapter
Next steps: Neon backend services
- Set up Managed Better Auth: Add managed authentication that branches with your database
- Add Object Storage: S3-compatible file storage that branches with your database
- Deploy a Function: Run backend compute next to your database, no separate hosting needed
- Call an LLM with AI Gateway: Access foundation models from Anthropic, OpenAI, Google, and more with one credential
Resources
Notes for AI-assisted setup
- Import
PrismaClientfrom./generated/prisma(or your configuredoutputpath), not from@prisma/client. The import path changed in Prisma 7. - Do not install
@neondatabase/serverlessorwsas separate packages. The@prisma/adapter-neonpackage bundles everything needed for the Neon connection. - In Prisma 7+, do not include a
urlproperty in theprisma/schema.prismadatasource block. The connection is configured in the Prisma config file and the adapter. npx prisma initin Prisma 7.10+ createsprisma7.config.ts. Edit that file instead of adding a secondprisma.config.ts; when both exist, the CLI loadsprisma7.config.ts.- You need both a pooled connection (
DATABASE_URL) for your application and a direct (unpooled) connection (DATABASE_URL_UNPOOLED) for Prisma CLI commands. - Call
prisma.$disconnect()in a.finally()block when running standalone scripts. Omitting this can leave connections open.
Need help?
Join our Discord Server to ask questions or see what others are doing with Neon. For paid plan support options, see Support.








