
Security News
OWASP 2025 Top 10 Adds Software Supply Chain Failures, Ranked Top Community Concern
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.
express-router-decorators
Advanced tools
Write your Express (4+) routers declaratively with ES2015 classes and ES decorators. TypeScript and Babel supported.
Write your Express (4+) routers declaratively with ES2015 classes and ES decorators. TypeScript and Babel supported.
Using express-router-decorators, you can define your Router controller as ES2015 class, which lets you keep cleaner and well-readable code. Remember to add @Root decorator to the class - this is a 'mounting point' of your router.
Particular paths in your router are defined using @Path decorator, which takes the path param (either string or regexp, as supported by Express) as its first argument. Second argument expects an http method name (string), but it is optional and defaults to 'get' (see the list of all http methods supported by express).
import * as express from 'express';
import { bindControllers, Root, Path } from 'express-router-decorators';
const app = express();
@Root('/greet')
class Greeter {
@Path('/hello')
hello (req, res) {
res.json({greeting: 'hello!'});
}
}
bindControllers(app, Greeter);
app.listen(1221, () => console.log('server ready at localhost:1221'));
Inheritance is also supported. You can extend your router classes with other classes!
The router created with Greeter class below will also have /hola route (inherited from SpanishGreeter class).
class SpanishGreeter {
@Path('/hola')
hola (req, res) {
res.json({greeting: 'hola!'});
}
}
@Root('/greet')
class Greeter extends SpanishGreeter {
@Path('/hello')
hello (req, res) {
res.json({greeting: 'hello!'});
}
}
npm install express-router-decorators --save
Make sure to add following two lines in the "compilerOptions" of your tsconfig.json file:
"experimentalDecorators": true,
"emitDecoratorMetadata": true
You will need "transform-decorators-legacy" plugin (npm install babel-plugin-transform-decorators-legacy --save-dev) in your .babelrc file, eg:
{
"presets": ["es2015", "stage-2"],
"plugins": ["transform-decorators-legacy"]
}
@Root(rootRoute: string) - class decorator used to define the router's mounting point.
rootRoute: string - router's mounting point (as known from Express: app.use('/mountingpoint', router)).@Path(pathRoute: string | RegExp, httpMethod?: string) - methods decorator that defines the routes within router's instance.
pathRoute: string | RegExp - defines the url path (obeying exactly the same rules as in barebones Express).httpMethod?: string - (optional) defines the HTTP method for given path (see the list of all http methods supported by express). Defaults to 'get'.@Use - methods decorator that defines the router's specific middleware. Takes no arguments.
bindControllers(app: Express, ...clazz: Function[]) - the 'main' function that 'connects' the router(s) class(es) to the Express application's instance.
app: Express - Express application's instance (eg. const app = express())....clazz: Function[] - (rest-parameters style) router class(es) decorated with @Root and @Path/@Use (see example).MIT
FAQs
Write your Express (4+) routers declaratively with ES2015 classes and ES decorators. TypeScript and Babel supported.
We found that express-router-decorators demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.