Express
@dotpress/adapter-express runs your app on Express 4 or 5.
Options
Express middlewares
Middlewares of the Express ecosystem go in beforeRoutes:
They run before Dotpress, for every request. Keep the logic of your API in Dotpress middlewares: they see the matched route and the typed context, run on every adapter, and are tested in memory.
An existing application
Pass your application with app: its settings, middlewares and routes stay, and the Dotpress routes are added to it. A project can move its routes to Dotpress one at a time.
Behavior
- Routes are matched by Dotpress, with the same rules on every adapter. Express settings such as
case sensitive routingorstrict routingdo not apply to them. - Bodies are read by the adapter: JSON, forms and text are parsed, and uploads without Multer. A body already parsed by a native middleware (
express.json(),multer…) is used as is. Routes declared withrawBody: trueneed the exact bytes: do not register a native body parser for them. - Errors passed to
next(error)by native middlewares use the Dotpress error format: a4xxstatusis kept, anything else is a500reported toonError. ctx.req.iphonors thetrust proxysetting of Express.ctx.rawis the Express request.close()waits for pending requests and closes the responses being streamed.adapter.server()returns the Node.js HTTP server started bylisten().
Your own HTTP server
To serve HTTPS from Node.js, or share a server, mount the Express application yourself:
AWS Lambda
The Express adapter has no Lambda entry. Your routes do not depend on the adapter: use the Hono or Fastify adapter on AWS Lambda, and keep Express for your servers if you like.
Example
The Express example is a tasks API with route groups, validation, returned errors, OpenAPI, and tests in memory and over HTTP.
useBeforeRoutes and useAfterRoutes of createApp() become the beforeRoutes and afterRoutes options of the adapter. createApp() no longer returns the Express application: use app.native().