Skip to main content

Claude/ChatGPT Prompt to Build a Scalable Node.js Express/Fastify API

Production Node.js + TypeScript API with layered architecture, Zod validation, JWT auth, structured logging, graceful shutdown, and health checks.

Füllen Sie die Platzhalter aus

Edit the values, then copy your finished prompt.

Ihr Prompt
prompt.txt

                                

What this prompt does

This prompt turns the model into a senior Node.js engineer that scaffolds a complete, production-ready API in TypeScript instead of toy snippets. It fixes the architecture up front — routes call services, services call repositories — so the handlers stay thin and the boring-but-critical pieces (validation, auth, logging, graceful shutdown, health checks) are wired in from the first file rather than retrofitted after an incident. Because it insists on working code over pseudocode, you get importable modules with real types, not illustrative fragments that fall apart when you connect them.

The [framework] variable swaps the HTTP layer between Express and Fastify, which changes the plugin and middleware idioms throughout. [domain] decides the example entities and routes the AI builds around, [auth] drives the JWT verification and how request.user is typed, and [node_version] pins both the language features it can use and the base image in the multi-stage Dockerfile. Naming all four narrows the output from a generic template to a service you could actually drop into your repo, with each layer demonstrating the dependency boundaries the prompt asks for.

When to use it

  • Starting a brand-new Node + TypeScript backend and you want the layered skeleton correct on day one.
  • Standardising how every service in a team handles validation, logging, and shutdown.
  • Replacing a quick prototype that grew real traffic and now needs readiness probes and pool draining.
  • Teaching a junior the difference between a demo API and one that survives a rolling deploy.
  • Generating an OpenAPI spec and Dockerfile alongside the code so deployment isn't an afterthought.
  • Auditing an existing service against a reference structure to find missing reliability pieces.

Example output

You get a printed file tree first, then the contents of the key files: the entry point, one route, one service, one repository, the config module, and a multi-stage Dockerfile. Request bodies, queries, and params each have a Zod schema funnelled through a single validation middleware, and request.user arrives typed after the JWT check. Structured pino logging carries a request-id for correlation, secrets are redacted, and the /healthz and /readyz endpoints sit alongside a SIGTERM handler that drains in-flight work. The shape is a coherent slice you can extend rather than a wall of disconnected fragments.

Pro tips

  • Set [framework] deliberately — Fastify's plugin model and Express's middleware chain produce noticeably different code, so don't leave it vague.
  • Make [node_version] match what your CI and base image actually run; a mismatch between the pinned Dockerfile and your toolchain causes subtle build breaks.
  • Wire the SIGTERM drain and /readyz (deliverable 5) before you containerise — orchestrators kill pods that report ready while still booting.
  • Describe [domain] in real nouns from your product so the example route, service, and repo map onto entities you'll keep.
  • If [auth] is an external provider rather than plain JWT, say so explicitly so the verification and request.user typing match that provider's tokens.
  • Paste an existing route afterward and ask it to conform to the generated structure when you're adding to a service, not starting fresh.

Frequently Asked Questions

Does this prompt support both Express and Fastify?
Yes. The `[framework]` variable selects which HTTP framework the generated code targets, and the plugin, middleware, and routing idioms change accordingly. Set it explicitly because the two frameworks produce meaningfully different scaffolding rather than interchangeable boilerplate.
Will the generated code actually compile, or is it pseudocode?
The prompt instructs the model to return working TypeScript where every file compiles and runs, not pseudocode. In practice you should still run a typecheck and install the listed dependencies, since model output can drift on exact package versions or imports.
How does it handle authentication?
It wires JWT authentication through the `[auth]` variable, adds role checks, and gives you a typed `request.user`. If you use an external auth provider, name it in `[auth]` so the verification logic and token typing match that provider instead of generic JWT.
Does it cover deployment and health checks?
Yes. It generates `/healthz` and `/readyz` endpoints, graceful shutdown on SIGTERM that drains in-flight requests and closes the DB pool, plus a multi-stage Dockerfile pinned to `[node_version]`. These pieces are what let the service survive rolling deploys under load.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Mehr in Node.js & TypeScript Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support