Skip to content

Getting Started ​

The packages on this site add request parsing, CORS, rate limits, logging, metrics and more to a routup app. Each one is a separate npm package that you install alone and register with app.use().

Requirements ​

The plugins are ESM only and are developed and tested on Node.js 24 or later. Each package has routup as a peer dependency; some need further peers. A peer from this repository is named without a range; the package.json of the package that needs it holds the range.

PackageroutupOther peer dependencies
@routup/assets^6.3.0none
@routup/basic^6.3.0none
@routup/body^6.3.0none
@routup/cookie^6.3.0none
@routup/cors^6.3.0none
@routup/decorators^6.5.0@trapi/core ^2.3.0, @trapi/metadata ^2.3.0, @trapi/swagger ^2.3.0 (optional, for OpenAPI generation)
@routup/i18n^6.3.0ilingo ^6.2.1
@routup/logger^6.3.0none
@routup/prometheus^6.4.0prom-client >=15.0.0
@routup/query^6.3.0none
@routup/rate-limit^6.3.0none
@routup/rate-limit-redis^6.3.0@routup/rate-limit, redis-extension ^3.0.0
@routup/swagger-ui^6.3.0@types/swagger-ui-dist ^3.30.5

Installation ​

Install routup and the plugins you need, here the two of the sample below:

bash
npm install routup @routup/body @routup/cors

Register Plugins ​

ts
import { App, defineCoreHandler } from 'routup';
import { body, readRequestBody } from '@routup/body';
import { cors } from '@routup/cors';

export const app = new App();

app.use(cors({ origin: 'https://app.example.com' }));
app.use(body());

app.post('/echo', defineCoreHandler((event) => readRequestBody(event)));

The file exports the app; serve it from your entry file.

bash
curl -i -X POST http://localhost:3000/echo \
    -H 'origin: https://app.example.com' \
    -H 'content-type: application/json' \
    -d '{"title":"Write docs"}'
# HTTP/1.1 200 OK
# access-control-allow-origin: https://app.example.com
#
# {"title":"Write docs"}

app.use() also takes a handler: rateLimit() and logger() return one, and @routup/rate-limit-redis exports a store that you pass to rateLimit(). What a plugin is, and how to mount one on a path, is described in Plugins on routup.dev.

Order Matters ​

routup runs the handlers that match a request in the order they were registered (Registration order). A plugin installs its handlers at the position of its app.use() call, so a route registered before it answers the request before the plugin runs:

ts
import { App, defineCoreHandler } from 'routup';
import { body, readRequestBody } from '@routup/body';

export const app = new App();

// registered before body(): the body is never parsed for this route
app.post('/before', defineCoreHandler((event) => readRequestBody(event)));

app.use(body());

app.post('/after', defineCoreHandler((event) => readRequestBody(event)));
bash
curl -X POST http://localhost:3000/before -H 'content-type: application/json' -d '{"title":"Write docs"}'
# {}
curl -X POST http://localhost:3000/after -H 'content-type: application/json' -d '{"title":"Write docs"}'
# {"title":"Write docs"}

Register plugins that parse the request or set response headers before the routes that rely on them. Combining Plugins shows a full stack and the ordering pitfalls.

Plugins ​

Plugins lists every package by group, with a one-line summary and a link to its documentation.