Connect a Next.js application to Neon
Set up a Neon project in seconds and connect from a Next.js application
Next.js by Vercel is an open-source web development framework that enables React-based web applications. This topic describes how to create a Neon project and access it from a Next.js application.
To create a Neon project and access it from a Next.js application:
- Create a Neon project
- Create a Next.js project
- Add a Postgres client to your app
- Add your Neon connection details
- Connect to the Neon database
Create a Neon project
If you do not have one already, create a Neon project. Save your connection details including your password. They are required when defining connection settings.
- Navigate to the Projects page in the Neon Console.
- Click New Project.
- Specify your project settings and click Create Project.
Create a Next.js project
Create a Next.js project if you do not have one. For instructions, see Create a Next.js App, in the Vercel documentation.
Add a Postgres client to your app
Add a PostgreSQL client to your app, such as
Postgres.js. For instructions, refer to the postgres.js Getting started.
Add your Neon connection details
Add your Neon connection string to your
<user>is the database user.
<password>is the database user's password.
<hostname>the hostname of the branch's compute endpoint. The hostname has an
ep-prefix and appears similar to this:
<port>is the Neon port number. The default port number is
<database>is the name of the database. The default Neon database is
You can find all of the connection details listed above in the Connection Details widget on the Neon Dashboard. For more information, see Connect from any application. If you have misplaced your password, see Reset a password.
Connect to the Neon database
From your API handlers or server functions, connect to the Neon database with the Postgres client and your Neon connection details. For example:
Never expose your Neon credentials to the browser.