Neon
Neon ↗ is a fully managed serverless PostgreSQL. It separates storage and compute to offer modern developer features, such as serverless, branching, and bottomless storage.
To set up an integration with Neon:
-
You need to have an existing Neon database to connect to. Create a Neon database ↗ or load data from an existing database to Neon ↗.
-
Create an
elements
table using the Neon SQL editor. The SQL Editor allows you to query your databases directly from the Neon Console.CREATE TABLE elements (id INTEGER NOT NULL,elementName TEXT NOT NULL,atomicNumber INTEGER NOT NULL,symbol TEXT NOT NULL); -
Insert some data into your newly created table.
INSERT INTO elements (id, elementName, atomicNumber, symbol)VALUES(1, 'Hydrogen', 1, 'H'),(2, 'Helium', 2, 'He'),(3, 'Lithium', 3, 'Li'),(4, 'Beryllium', 4, 'Be'),(5, 'Boron', 5, 'B'),(6, 'Carbon', 6, 'C'),(7, 'Nitrogen', 7, 'N'),(8, 'Oxygen', 8, 'O'),(9, 'Fluorine', 9, 'F'),(10, 'Neon', 10, 'Ne'); -
Configure the Neon database credentials in your Worker:
You need to add your Neon database connection string as a secret to your Worker. Get your connection string from the Neon Console ↗ under Connection Details, then add it as a secret using Wrangler:
Terminal window # Add the database connection string as a secretnpx wrangler secret put DATABASE_URL# When prompted, paste your Neon database connection string -
In your Worker, install the
@neondatabase/serverless
driver to connect to your database and start manipulating data:Terminal window npm i @neondatabase/serverlessTerminal window yarn add @neondatabase/serverlessTerminal window pnpm add @neondatabase/serverless -
The following example shows how to make a query to your Neon database in a Worker. The credentials needed to connect to Neon have been added as secrets to your Worker.
import { Client } from '@neondatabase/serverless';export default {async fetch(request, env, ctx) {const client = new Client(env.DATABASE_URL);await client.connect();const { rows } = await client.query('SELECT * FROM elements');ctx.waitUntil(client.end()); // this doesn’t hold up the responsereturn new Response(JSON.stringify(rows));}}
To learn more about Neon, refer to Neon's official documentation ↗.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark