routing-controllers: where the routes live in decorated classes, and what the peer dependencies cost
Create structured, declarative and beautifully organized class-based controllers with heavy decorators usage in Express / Koa using TypeScript and Routing Controllers Framework.
At a glance
- What is it?
- The TypeStack library that turns decorated controller classes into Express or Koa routes, read from the install steps outward: the compiler flags it needs, the decorators that change both ends of a request, and the sample directory that doubles as the API tour.
- Who is it for?
- routing-controllers earns its place in a TypeScript service that already runs Express or Koa and wants each route described next to the code that handles it. It costs two compiler flags, an import you must not forget, and a say in when class-validator and class-transformer move under you.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Activity is slowing. The repository last received commits 6 months ago.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- typestack/routing-controllers4,501 ★ · -5
| Repository | 2026-09-23 | 2026-11-25 |
|---|---|---|
| typestack/routing-controllers | 4.5k | 4.5k |
-5 Stars in the last 63 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The route table is written in the class, not in a separate file
In routing-controllers the routes are not declared in a configuration file. They sit in the class: @Controller() marks it, and each method decorator carries its own path, so @Get('/users') and @Get('/users/:id') live on the methods that serve them. createExpressServer then registers those paths with the framework and returns the app instance.
import 'reflect-metadata';
import { Controller, Param, Body, Get, Post, Put, Delete } from 'routing-controllers';
@Controller()
export class UserController {
@Get('/users')
getAll() {
return 'This action returns all users';
}
@Get('/users/:id')
getOne(@Param('id') id: number) {
return 'This action returns user #' + id;
}
@Post('/users')
post(@Body() user: any) {
return 'Saving user...';
}
}Two details in that sample deserve copying exactly. Parameters arrive through decorators as well, @Param('id') for a path segment and @Body() for the request body, so the method signature carries the whole contract. And the shim import comes first in the file, not in a central bootstrap.
Koa users swap one function, createKoaServer for createExpressServer, and keep every decorator. That is the strength of the design and also its limit, since anything specific to one framework has to travel through the request and response objects the action receives.
Five npm commands, two compiler flags, and a shim that must be imported
The install is short and every part of it carries weight:
npm install routing-controllers
npm install reflect-metadata
npm install express body-parser multer
npm install -D @types/express @types/body-parser @types/multer
npm install class-transformer class-validatorThe reflect-metadata shim has to be imported before routing-controllers is used, and the compiler has to be told to emit decorator metadata:
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
}Koa installs a different set: npm install koa @koa/router koa-bodyparser @koa/multer, with npm install -D @types/koa @types/koa-bodyparser for the typings. The choice is made at install time rather than at runtime, because body parsing and file uploads come from a different package on each side.
class-transformer and class-validator moved to peer dependencies
Those two packages used to be direct dependencies and are now peer dependencies, and the stated reason is timing: as peer dependencies you choose when to upgrade and accept breaking changes on your own schedule.
The practical effect is that an install can look complete while the half that turns parameters into objects and checks them is missing. The features that lean on those packages, converting parameters to objects, auto validating action params, making a parameter required, are the ones that go quiet.
The accepted ranges are narrow: class-transformer at ^0.5.1 and class-validator at ^0.14.1. A project that already sits on a newer major of either has to reconcile versions before it can use the decorators that depend on them, which is exactly the kind of pause the peer dependency move was meant to hand you.
@Controller sends text, @JsonController guarantees the body
Two decorators decide what a response looks like. @Controller gives you a plain action, and the sample returns the string 'This action returns all users', which the browser shows as text. @JsonController guarantees the other behavior: whatever an action returns is transformed to JSON, the Content-Type header is set to application/json on the way out, and an application/json request body is understood and parsed on the way in.
That guarantee is opt in, which is where projects get caught.
The feature list also names sections for setting a custom ContentType, Location, Redirect and HTTP code, for custom headers, for controlling empty responses, for rendering templates, for throwing HTTP errors, for enabling CORS, and for default settings. The response side is therefore configured decorator by decorator rather than through one piece of middleware, and there is a separate section on selectively disabling request and response transforming for endpoints that are not JSON.
Middlewares, interceptors and authorization share one decorator grammar
Everything else in the library is the same grammar pointed at a different job, and that is where the reading pays off. Middlewares can be an existing package, your own express or koa middleware, global ones applied across routes, or error handlers, and both middlewares and controllers can be loaded from directories instead of a hand written list. Interceptors come as a plain function, as a class, or as global interceptors. The parameter decorators cover routing parameters, query parameters, the body and its fields, request headers, cookies, the session object, a state object, uploaded files, and making a parameter required.
Authorization sits on the same decorators, with @Authorized on an action and @CurrentUser to pull the authenticated user into a parameter. Around those sit auto validating action params, creating instances of classes from action params, a DI container, and custom parameter decorators.
The sample directory is the API tour, and it skips two numbers
The quickest way through the API is the sample directory, and its numbering is not a sequence. It holds sample1-simple-controller, sample2-controllers-from-directory, sample3-promise-support, sample4-extra-parameters, sample5-http-errors, sample6-global-middlewares, sample7-parsed-models, sample9-use-and-middlewares, sample11-complete-sample-express, sample12-session-support, sample13-koa-views-render, sample14-custom-decorator, sample15-authorized, sample16-current-user and sample17-controllers-inheritance, each one a directory of its own.
The names line up one for one with the feature sections: controllers loaded from a directory, promise support, http errors, global middlewares, parsed models, session support, koa views, a custom decorator, authorized actions, the current user decorator, controller inheritance. The run stops at sample7 and picks up at sample9, so there is no sample8 and no sample10, which means any guide that sends you to sample10 sends you nowhere. Read the folder names rather than trusting the number, and expect the complete express sample at sample11 to be the one that shows how the pieces fit together. The koa view rendering sample is the counterpart for the createKoaServer path.
A fixed debug port, three build targets, and version 0.11.3
package.json describes how the library is built and tested, and one script stands out:
"test": "jest --verbose --runInBand",
"test:ci": "jest --runInBand --no-cache --coverage --verbose",
"test:debug": "NODE_ENV= node --inspect=0.0.0.0:20001 ./node_modules/.bin/jest --colors --runInBand --no-coverage --watch"The debug script binds one fixed port, 20001, on all interfaces, so two checkouts on the same machine, or a worker already running a debugger, will collide. The rest is conventional: jest.config.js and jest.setup.js sit at the top level, lint runs eslint with --max-warnings 0 over src, prettier covers ts and md files, and the build has three targets producing cjs into ./cjs/index.js, es2015 into ./esm2015/index.js and types into ./types/index.d.ts, which are exactly the fields main, module and typings point at. Runtime dependencies are short, cookie, glob, reflect-metadata and template-url.
On versions, package.json reads 0.11.3, the newest tag v0.11.3 was published on 2025-08-05 after v0.11.2 in March 2025 and v0.11.1 in February 2025, and the default branch is develop, which took a push on 2026-05-23.
Editorial conclusion
routing-controllers earns its place in a TypeScript service that already runs Express or Koa and wants each route described next to the code that handles it. It costs two compiler flags, an import you must not forget, and a say in when class-validator and class-transformer move under you. Check three things before committing: that tsconfig.json sets emitDecoratorMetadata and experimentalDecorators, that the peer dependencies sit at the ranges package.json names, and that you chose between @Controller and @JsonController deliberately. For a plain JavaScript service it is the wrong tool, since the design rests on decorator metadata.
Frequently asked questions
What is the difference between a router and a controller?
In this library the two are not alternatives. A controller class carries the paths in its method decorators, such as @Get('/users/:id'), and createExpressServer or createKoaServer registers them with the framework underneath. The router is the express or koa layer that holds the resulting route table; the controller is the class that decides which path maps to which method.
What is the difference between controllers and routes?
A route is a path plus a handler in the underlying framework. Here the controller is where the path is written: @Get('/users') decorates a method, and the class registration turns that method into a route when createExpressServer runs with the controllers listed. Routes end up on the server whether or not you wrote them by hand, because the decorators generate them.
How do I install routing-controllers with Express?
Run npm install routing-controllers, npm install reflect-metadata, and npm install express body-parser multer, then add npm install -D @types/express @types/body-parser @types/multer for the typings. Set emitDecoratorMetadata and experimentalDecorators to true in tsconfig.json and import 'reflect-metadata' before you use the library.
Does routing-controllers work with Koa?
Yes, with koa 2. Install npm install koa @koa/router koa-bodyparser @koa/multer and the typings with npm install -D @types/koa @types/koa-bodyparser, then create the server with createKoaServer instead of createExpressServer. The decorators stay the same, and the sample directory includes a koa views sample.
Why does routing-controllers need reflect-metadata?
The reflect-metadata shim is required, and it has to be imported before routing-controllers is used, because the library reads the type information that the compiler attaches to parameters. tsconfig.json needs emitDecoratorMetadata and experimentalDecorators set to true for that information to exist, so without them the decorators cannot tell a number from a string.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/typestack-routing-controllers)Star history chart for your README
[](https://hysenlabs.com/projects/typestack-routing-controllers)Was this useful?