Generate an Express 5 or Express 4 JSON API starter, with async error handling and route patterns written for the major version you pick.
Express 5 routes async rejections to the error middleware itself, so no wrapper is generated. Wildcards are named: /*splat.
13 files, internally consistent.
Imports, dependencies, scripts and configuration agree. Nothing was compiled or run — see Checks.
src/app.tsBuilds the app without listening, so tests can import it and the server file owns the port.
import express from "express";
import type { Express, NextFunction, Request, Response } from "express";
import cors from "cors";
import helmet from "helmet";
import { config } from "./config.js";
import { errorHandler, notFound } from "./middleware/errors.js";
import { requestLogger } from "./middleware/request-logger.js";
import { itemsRouter } from "./routes/items.js";
/* The app is built here and started in server.ts. Keeping them
separate is what lets a test import the app and make requests
against it without binding a port. */
export function createApp(): Express {
const app = express();
app.use(helmet());
app.use(
cors({
/* An explicit origin, not true. Reflecting any origin with
credentials enabled lets any site read authenticated
responses on a user's behalf. */
origin: config.corsOrigin,
credentials: true,
}),
);
/* A body size limit. The default is 100kb, which is usually right;
it is written out so that raising it is a decision rather than an
accident. */
app.use(express.json({ limit: "100kb" }));
app.use(requestLogger);
app.get("/health", (_req: Request, res: Response) => {
res.json({ status: "ok", uptime: process.uptime() });
});
app.use("/items", itemsRouter);
/* Order matters: the 404 handler must come after every route, and the
error handler after that. Express picks middleware in the order it
was registered. */
app.use(notFound);
app.use(errorHandler);
return app;
}
The two majors get separate templates rather than one template with the version swapped. Mixing them is the usual failure: an Express 4 wildcard throws at startup under Express 5, and an Express 4 project without the async wrapper hangs a request instead of erroring. The output is ESM, so relative imports carry the .js extension that Node requires.
Express API Scaffold runs entirely on your device — the files are generated in your browser from templates built into the page, nothing is installed or run, and your project name and options are not sent anywhere.
You’re on the Free plan. Compare plans
Express 4 and Express 5 need different code, and the differences are the kind that produce an application which starts and then misbehaves. So this holds two templates rather than one with a version number swapped in.
The two that matter most. Express 5 forwards a rejected promise from an async handler to the error middleware by itself; Express 4 does not, and an unhandled rejection leaves the request hanging until the client gives up. And Express 5 uses path-to-regexp 8, where a wildcard must be named — `/*splat` works and a bare `/*` throws at startup, so an Express 4 route copied into an Express 5 project stops the server booting.
Beyond the version, the arrangement is the opinionated part. The app is built in one file and started in another, so a test can import it without binding a port. Errors go through one class that carries a status code, so no handler writes a status itself and nothing below 500 leaks an internal message. The request logger runs on response finish, because that is the first moment the status code exists. CORS takes an explicit origin rather than reflecting whatever asked, which with credentials enabled would let any site read authenticated responses.
Every file is checked against the others before you see it: imports resolve to generated files, declared dependencies match what is imported, the relative imports carry the `.js` extension that ESM requires, and the environment example is checked for anything resembling a real credential.
Nothing is compiled, installed or run. The check is structural, the page says so, and the templates themselves are parsed by the real TypeScript parser in this site's test suite.
Because Express 5 does not need one — it routes a rejected promise to the error middleware itself. Generating the wrapper anyway would teach a workaround for a problem the version you picked does not have.
Because Express 4 never sees the rejection. Without the wrapper an async handler that throws leaves the request open until the client times out, with nothing logged and no response sent.
Because the output is ESM with NodeNext resolution, where the specifier names the emitted file. It looks wrong and is required; omitting the extension fails at runtime with a message that does not mention it.
No. Imports, dependencies, scripts and configuration are checked against each other, and nothing is installed, type-checked or executed. The page states exactly what was and was not checked.
The async wrappers become unnecessary and every route pattern needs reading: a bare wildcard and an optional parameter both throw under Express 5. Generating the 5 version here and comparing is a quick way to see the work.
If a tool here saved you some time, you can put something towards the hosting.Buy me a coffee, on Ko-fi, opens in a new tab