This is a simple API of a serverless API using Cloudflare Workers, Drizzle ORM and Neon. It returns a list of products from a Neon database. If you would like to learn how to build this project from scratch, check out the tutorial: https://neon.tech/blog/api-cf-drizzle-neon
You will need the following:
- A Cloudflare account and the wrangler CLI installed
- A Neon account and a project
- Clone the repository
git clone https://github.com/neondatabase/cloudflare-drizzle-neon.git
cd neon-cloudflare-drizzle
npm install
- Copy the
.dev.vars
file by running the following command:
cp .dev.vars.example .dev.vars
-
Update the
.dev.vars
file with your Neon connection string. -
Run the following command to apply the existing database migrations located in the
/drizzle
directory:
npm run migrate
- In the Neon console, run the following query in the Neon's SQL editor:
INSERT INTO products (name, price, description) VALUES
('Product A', 10.99, 'This is the description for Product A.'),
('Product B', 5.99, 'This is the description for Product B.'),
('Product C', 15.99, 'This is the description for Product C.'),
('Product D', 8.99, 'This is the description for Product D.'),
('Product E', 20.99, 'This is the description for Product E.');
- Run the following command to start the server:
npm run start
- Open the browser at
http://localhost:8787
to see the list of products.