Scaffolding APIs
Scaffolding creates a consistent starting point so every new service has the same layout, scripts, and quality gates.
Search across all documentation pages
Scaffolding creates a consistent starting point so every new service has the same layout, scripts, and quality gates.
Quick-reference recipe card - copy-paste ready.
mkdir orders-api && cd orders-api
npm init -y
npm install express@5
npm install -D typescript@5.6 tsx @types/node @types/express eslint
npx --yes @nestjs/cli new orders-api --package-manager npm --strictWhen to reach for this:
# 1. Org template (preferred for teams)
git clone git@github.com:acme/node-api-template.git billing-api
cd billing-api
rm -rf .git && git init
npm ci
# 2. Or minimal manual scaffold
npm init -y
npm pkg set type=module
npm pkg set scripts.dev="tsx watch src/server.ts"
npm pkg set scripts.build="tsc -p tsconfig.build.json"
npm pkg set scripts.start="node dist/server.js"
npm pkg set scripts.test="node --import tsx --test"
npm install express@5
npm install -D typescript@5.6 tsx @types/node @types/express
npx tsc --init --module NodeNext --moduleResolution NodeNext --strict
mkdir -p src test// src/server.ts
import express from "express";
export function createApp() {
const app = express();
app.use(express.json());
app.get("/health", (_req, res) => res.json({ ok: true }));
return app;
}
if (import.meta.url === `file://${process.argv[1]}`) {
createApp().listen(3000);
}What this demonstrates:
npm pkg set scripts without hand-editing JSON.createApp() export enables Supertest integration tests from day one.npm init creates package.json; frameworks add routing, DI, and conventions.nest-cli.json build graph.npm ci && npm test in CI to prove they work.| CLI | Command | Best for |
|---|---|---|
| NestJS 11 | npx @nestjs/cli new | Opinionated modules, DI, enterprise APIs |
| Fastify 5 | manual + @fastify/type-provider-typebox | Performance-first HTTP |
| Express 5 | manual / org template | Minimal middleware stacks |
npm install -D typescript@5.6 tsx
# tsconfig: "module": "NodeNext", "strict": truemodule settings you use in production builds.test/ and a sample test in the template so CI is never empty.--package-manager npm. Fix: script the flags in docs.createApp export - Hard to integration-test servers that only call listen() at import. Fix: export factory; start server in if (main) guard..env.example in templates.
| Alternative | Use When | Don't Use When |
|---|---|---|
Internal npm create @acme/api | Standardized org generator | Solo experiments |
Turborepo create-turbo | Monorepo from day one | Single microservice |
Defer framework, raw node:http | Learning or ultra-minimal probe | Production CRUD APIs |
Framework CLIs for NestJS; org templates for Express/Fastify where you want custom layout. npm init alone is never enough for production APIs.
Treat it as a product: CI, dependency bumps, changelog, tagged releases. New services pin a template version or branch.
package.json scripts, tsconfig, .gitignore, .env.example, Dockerfile, sample test, ESLint config, and README quick start.
Yes. Run generator inside apps/billing-api and wire root workspaces after. Update root turbo.json pipeline.
Follow org ADR. Fastify for throughput-sensitive APIs; Express for largest middleware ecosystem and team familiarity.
CI job: clone fresh, npm ci, npm test, npm run build, Docker build. Fail template release if any step fails.
Only if standardized org-wide. Otherwise add data layer in a second PR to keep templates framework-agnostic longer.
Include Husky + lint-staged optional profile. Document skip for contributors who rely on CI-only gates.
Update package.json name, K8s manifests, and Docker image tags. Nest project name propagates to several files.
Pin CLI version in devDependencies or use npx @nestjs/cli@11.x for reproducible generation docs.
Stack versions: This page was written for Node.js 24.18.0 (Active LTS), npm 10+, TypeScript 5.6+, Express 5, Fastify 5, and NestJS 11.
Reviewed by Chris St. John·Last updated Jul 19, 2026