# Node Next.js PostgreSQL event tickets

A workshop ticket site shows live availability, accepts orders for up to six seats, and issues a ticket code after checkout. Tokay runs the Next.js app as one Web Service with PostgreSQL, so orders and seat counts survive every deployment.

You can try the complete experience without opening a payment account. The built in free test mode follows the same order and ticket path, while optional Stripe test keys let you connect a real hosted checkout later.

## Facts

- Runtime: Node.js
- Framework: Next.js
- Service types: Web Service
- Resources: PostgreSQL
- Required secrets: None

## What it does

The event page shows the workshop date, venue, price, and current number of seats left.

Use the minus and plus buttons to choose between one and six seats. Press **Complete free test order** and the next page gives you a ticket code with your reservation details.

When Stripe test mode is connected, the button changes to **Continue to Stripe test checkout**. The app waits for Stripe's signed confirmation before it issues that ticket.

## Deploy it

Bring this folder to Tokay any way you like. Paste or upload it in the dashboard, push it with git, or hand it to your AI agent along with [our agent instructions](https://app.tokay.io/llms.txt). Tokay figures out the rest.

Working in Claude, ChatGPT, VS Code, or another MCP client? Connect the [Tokay MCP server](https://tokay.io/docs/platform-mcp) and ask your agent to deploy this example. It signs in through your browser, so there is no token to paste.

New to Tokay? The [getting started guide](https://tokay.io/getting-started) walks you through your first deploy.

## Finish setup in Tokay

The ticket app needs PostgreSQL to keep orders and ticket codes. Open **Environment** and find `DATABASE_URL` under **From your infrastructure**. Confirm the suggested database, leave its name as `app`, and finish with **Confirm**.

Finish the deployment tracker once `DATABASE_URL` shows **Good to go**. Choose **Go Live** if Tokay asks. The live URL at the top of the finished Service opens the event page.

## Try it

1. Choose two seats and press **Complete free test order**.
2. Save the ticket page URL, then deploy the same code again.
3. Open that URL. Your ticket code remains, and the event page still counts both seats.

## Add Stripe test checkout

Use the live Service URL that already works in free test mode.

1. Create a Stripe test mode secret key.
2. In Stripe, add a test webhook endpoint using your live URL followed by `/api/stripe/webhook`.
3. Subscribe that endpoint to `checkout.session.completed`, then copy the webhook signing secret Stripe creates for it.
4. Open the Service's **Environment** page. Find `STRIPE_SECRET_KEY` and `STRIPE_WEBHOOK_SECRET` under **From your code**.
5. Choose **Set shared value** for each one, paste the matching value, and save it.
6. Deploy the Service again.

The checkout button will now open Stripe in test mode. Complete a payment with a Stripe test card, then return to the ticket page. The app waits for Stripe's signed confirmation before issuing the ticket.

## How it works

You get a current seat count in the first page response because Next.js reads PostgreSQL on the server. The browser handles quantity changes and starts checkout, while the database keeps each order and ticket code.

Drizzle keeps the schema with the source. Tokay rehearses its committed migration before applying it. Free test orders complete in one transaction, while Stripe orders remain pending until a valid signed webhook arrives.

## Secrets

| Name | Required | Purpose |
| --- | --- | --- |
| `STRIPE_SECRET_KEY` | No | Enables Stripe test checkout when the webhook secret is also set. |
| `STRIPE_WEBHOOK_SECRET` | No | Verifies Stripe completion events before a ticket is issued. |

## Grow from here

Try the [PostgreSQL task tracker](/examples/node-express-postgres-task-tracker) when you want a smaller app with a detailed JSON API.

## Source files

- [app/api/checkout/route.ts](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/app/api/checkout/route.ts)
- [app/api/health/route.ts](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/app/api/health/route.ts)
- [app/api/stripe/webhook/route.ts](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/app/api/stripe/webhook/route.ts)
- [app/checkout.tsx](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/app/checkout.tsx)
- [app/layout.tsx](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/app/layout.tsx)
- [app/page.tsx](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/app/page.tsx)
- [app/styles.css](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/app/styles.css)
- [app/tickets/\[id\]/page.tsx](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/app/tickets/%5Bid%5D/page.tsx)
- [db/client.ts](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/db/client.ts)
- [db/schema.ts](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/db/schema.ts)
- [drizzle.config.ts](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/drizzle.config.ts)
- [drizzle/0000\_create\_event\_tickets.sql](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/drizzle/0000_create_event_tickets.sql)
- [drizzle/meta/\_journal.json](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/drizzle/meta/_journal.json)
- [next-env.d.ts](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/next-env.d.ts)
- [package.json](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/package.json)
- [server.js](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/server.js)
- [tsconfig.json](https://tokay.io/examples/src/node-nextjs-postgres-event-tickets/tsconfig.json)

## Download and source

- [Download the complete project](https://tokay.io/examples/downloads/node-nextjs-postgres-event-tickets.zip)
- Last updated: 2026-07-31
- Example revision: `52c7b7f`
- [View this revision on GitHub](https://github.com/tokayio/tokay-examples/tree/52c7b7ffd52e157375b08f1f11ff4fbe6c498642/node-nextjs-postgres-event-tickets)
- [Deploy a Next.js app](https://tokay.io/use-cases/deploy-nextjs)
