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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ppirogov/express-decorators

v1.0.3

Published

This library provides a set of **TypeScript** decorators to simplify route handling and dependency injection in Express applications. It includes route decorators like GetMapping, PostMapping, and ExpressController to streamline route registration, as wel

Downloads

4

Readme

Decorators for Express

This library provides a set of TypeScript decorators to simplify route handling and dependency injection in Express applications. It includes route decorators like GetMapping, PostMapping, and ExpressController to streamline route registration, as well as Autowire and AutowireComponent for managing components and automatic dependency injection, enabling a clean, modular, and declarative approach to building Express-based applications.

ExpressMapping

The main decorator that handles binding a route to a controller method. It takes a path and an HTTP method (GET, POST, PUT, DELETE, USE) and registers the corresponding route in the Express application.

GetMapping, PostMapping, PutMapping, DeleteMapping, UseMapping Specialized decorators that call ExpressMapping with a specific HTTP method.

Decorators for Managing Controllers and Components

ExpressController: A decorator that registers a controller class to be used in your Express application.

AutowireComponent: A decorator for registering a class as a component that can be automatically injected into other parts of the application.

Autowire: A decorator for automatically injecting dependencies into the fields of other classes.

@ExpressController

Class decorator for express controllers

@ExpressController
export class SampleController {}

on import automatically creates instance and registers it.

@ExpressMapping

Creates method decorator that registers method in express app.

@ExpressMapping('/api/sample', 'get')
emptyObjectGet(req: Request, res: Response) {
  res.setHeader('Content-Type', 'application/json');
  res.send({});
}

@GetMapping

Uses ExpressMapping with predefined request method "get"

@GetMapping('/api/sample')
emptyObjectGet(req: Request, res: Response) {
  res.setHeader('Content-Type', 'application/json');
  res.send({});
}

@PostMapping

Uses ExpressMapping with predefined request method "post"

@PutMapping

Uses ExpressMapping with predefined request method "put"

@DeleteMapping

Uses ExpressMapping with predefined request method "delete"

@UseMapping

Uses ExpressMapping with predefined request method "use"

@AutowireComponent

Class decorator for autowire components

@AutowireComponent
export class SampleService implements SampleServiceInterface {}

on import automatically creates instance and registers it.

@Autowire

Field decorator that set's instance of registered AutowireComponent

@Autowire("SampleService")
sampleService: SampleServiceInterface;

Usage

First create and register Express app so decorators can work with it.

const app: Express = express();
registerExpressApp(app);

then import AutowireComponent's

then import ExpressController's

It's important to keep order of imports.

Import AutowireComponent first and then import component that uses it with Autowire decorator.