npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

deco-express

v0.2.0

Published

Decorator-based utilities for building Express.js REST APIs in TypeScript

Downloads

40

Readme

deco-express

Decorator-based utilities for building Express.js REST APIs in TypeScript.

deco-express reduces boilerplate when building Express applications by providing a small set of TypeScript decorators for defining controllers, routes, and request validation.


Installation

npm install deco-express reflect-metadata

reflect-metadata is a required peer dependency. Import it once at the entry point of your application before using any decorators.

// src/main.ts
import 'reflect-metadata';

Also ensure your tsconfig.json includes:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Quick Start

import 'reflect-metadata';
import express from 'express';
import Joi from 'joi';
import { Controller, Route, Validate, defineRoutes } from 'deco-express';

const createUserSchema = Joi.object({
  name: Joi.string().required(),
  email: Joi.string().email().required(),
});

@Controller('/users')
class UserController {
  @Route('get', '/list')
  async list(req, res) {
    res.json({ users: [] });
  }

  @Validate(createUserSchema)
  @Route('post', '/create')
  async create(req, res) {
    res.status(201).json({ created: req.body });
  }
}

const app = express();
app.use(express.json());

defineRoutes([UserController], app);
// Registers:
//   GET  /api/v1/users/list
//   POST /api/v1/users/create

app.listen(3000);

API Reference

@Controller(baseRoute?)

Class decorator. Marks a class as a route controller and sets its base path.

| Parameter | Type | Default | Description | | ----------- | -------- | ------- | ------------------------------- | | baseRoute | string | '' | Base path prefix for all routes |

@Controller('/products')
class ProductController { ... }

@Route(method, path?, ...middleware)

Method decorator. Maps a class method to an HTTP route.

| Parameter | Type | Default | Description | | ------------ | ------------------ | ------- | ------------------------------------ | | method | keyof Express | — | HTTP method (get, post, etc.) | | path | string | '' | Route path (appended to base route) | | middleware | RequestHandler[] | [] | Optional Express middleware to apply |

@Route('get', '/list', authMiddleware)
async list(req, res) { ... }

@Validate(schema)

Method decorator. Validates req.body against a Joi schema before the handler runs. Returns 422 Unprocessable Entity on validation failure with structured error details.

| Parameter | Type | Description | | --------- | ------------ | ------------------------------ | | schema | Joi.Schema | Joi schema to validate against |

@Validate(Joi.object({ name: Joi.string().required() }))
@Route('post', '/create')
async create(req, res) { ... }

Error response format (422):

{
  "message": "Validation failed",
  "details": [{ "field": "name", "message": "\"name\" is required" }]
}

defineRoutes(controllers, app, addApi?, version?)

Registers all decorated controller routes to an Express application.

| Parameter | Type | Default | Description | | ------------- | --------------- | ------- | -------------------------------------- | | controllers | Constructor[] | — | Array of controller class constructors | | app | Express | — | Express application instance | | addApi | boolean | true | Prepend /api to all routes | | version | number | 1 | API version number (e.g. /v1) |

defineRoutes([UserController, ProductController], app, true, 2);
// Routes become: /api/v2/...

defineRoutes([UserController], app, false);
// Routes become: /users/...

Route Path Construction

The final route path is built as:

/{api}/{version}/{baseRoute}/{path}

| addApi | version | Result prefix | | -------- | --------- | ------------- | | true | 1 | /api/v1 | | true | 2 | /api/v2 | | false | any | (no prefix) |


License

MIT