---
title: "Build a serverless API using Cloudflare Workers, Drizzle ORM, and Neon"
description: "A step-by-step setup for a serverless TypeScript API on Cloudflare Workers that uses Hono for routing, Drizzle ORM for schema definition and migrations, and Neon serverless Postgres for storage."
url: "https://swe.quest/articles/build-a-serverless-api-using-cloudflare-workers-drizzle-orm-and-neon-f83c472c9d399a17"
canonical: "https://neon.com/blog/api-cf-drizzle-neon"
source: "Neon"
published: "2023-05-30"
difficulty: "medium"
kind: "How-to"
reading_minutes: 9
tags: ["serverless","postgres","typescript","schema-migrations"]
---

# Build a serverless API using Cloudflare Workers, Drizzle ORM, and Neon

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-05-30, 9 min read, How-to. Original: [https://neon.com/blog/api-cf-drizzle-neon](https://neon.com/blog/api-cf-drizzle-neon)

## Summary

A step-by-step setup for a serverless TypeScript API on Cloudflare Workers that uses Hono for routing, Drizzle ORM for schema definition and migrations, and Neon serverless Postgres for storage. It scaffolds a Worker with create-cloudflare, defines a products table in TypeScript, and uses drizzle-kit to generate SQL migrations. Migrations run through a postgres.js script capped at a single connection so they execute in order. The Worker queries Neon over HTTP via @neondatabase/serverless, is deployed with wrangler, and gets its DATABASE\_URL from Cloudflare's Neon integration instead of manually configured secrets.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)
- [Schema migrations](https://swe.quest/tags/schema-migrations.md) (Data & databases)

## Prerequisites

- TypeScript basics ([easy posts on TypeScript](https://swe.quest/tags/typescript.md?difficulty=easy))
- Node.js and npm ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- basic SQL ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))

## Keywords

Cloudflare Workers, Neon, Drizzle ORM, Hono, drizzle-kit, wrangler, @neondatabase/serverless

## Related posts

- [Build and Deploy a Global Serverless Nuxt SSR App with Cloudflare Hyperdrive and Postgres](https://swe.quest/articles/build-and-deploy-a-global-serverless-nuxt-ssr-app-with-cloudflare-hyperdrive-32566cf4580232ef.md): Neon · 2024-04-05 · Medium · 12 min read · Serverless, PostgreSQL, CDN & edge, JavaScript, Caching
  A Nuxt SSR app on Cloudflare Pages can query Neon Postgres through Hyperdrive by routing Drizzle's pg-proxy driver to a separate Hono-based Cloudflare Worker that holds the Hyperdrive binding and runs queries with node-postgres.
- [@neondatabase/serverless hits 1.0.0](https://swe.quest/articles/neondatabase-serverless-hits-1-0-0-d5430675bc92b751.md): Neon · 2025-03-25 · Medium · 5 min read · PostgreSQL, Serverless, TypeScript, Application security, JavaScript
  Neon's JavaScript/TypeScript serverless driver, which carries Postgres queries over HTTP and WebSockets for environments without raw TCP such as V8 isolates and browsers, reaches 1.0.0 after a refactor that adds auto-generated types via api-extractor and CI tests across Node, Bun, Deno, browsers, Cloudflare Workers, Vercel and the Prisma/Drizzle adapters.
- [Build a Serverless API using AWS Lambda, CDK, and Neon](https://swe.quest/articles/build-a-serverless-api-using-aws-lambda-cdk-and-neon-939349a37c380ca9.md): Neon · 2023-11-30 · Medium · 11 min read · Serverless, Infrastructure as code, PostgreSQL, Cloud platforms, TypeScript
  A step-by-step build of a single-endpoint REST API on AWS Lambda, defined with AWS CDK v2 in TypeScript, that returns a product list from a Neon serverless Postgres database.
- [Introducing neon.ts: infrastructure as code for your Neon projects](https://swe.quest/articles/introducing-neon-ts-infrastructure-as-code-for-your-neon-projects-a40f6e284c0cef8b.md): Neon · 2026-06-15 · Medium · 8 min read · Infrastructure as code, TypeScript, PostgreSQL, Serverless, Developer tools
  neon.ts is a TypeScript infrastructure-as-code file for Neon projects that declares services (Postgres, Neon Auth, Data API, with functions, buckets and an AI gateway coming under a preview block) and provisions them with \`neon config plan\` and \`neon config apply\`.
- [Build a Database App with Drizzle ORM and Deno](https://swe.quest/articles/build-a-database-app-with-drizzle-orm-and-deno-692f9df52f193839.md): Deno · 2024-11-13 · Medium · 7 min read · TypeScript, PostgreSQL, JavaScript, Schema migrations
  Drizzle ORM can be used from Deno via npm compatibility to get type-safe CRUD access to PostgreSQL.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
