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

night-decorator

v1.2.3

Published

路由装饰器

Downloads

3

Readme

本项目是基于express封装的路由装饰器,可自动引入控制器,并以装饰器方式引入路由地址

github 项目地址:(https://github.com/by-night/decorator)

下载

npm install night-decorator

1. 使用说明:

参数

autoRouter(Router, [options])

  • Router: 路由实例
  • options: 路由配置 (可选参数)

路由配置[options]:

  • 路由路径:默认为根目录的controller目录,可用过options的 con_path 配置项修改
  • 拦截器路径:默认为根目录的interceptor目录,可用过options的 inter_path 配置项修改
app.use(autoRouter(Router, {
    con_path: '/src/controller',
    inter_path: '/src/interceptor'
}));

2. 示例:

  • 在根文件(一般为app.js) 中使用:
const express = require("express");
const autoRouter = require('night-decorator');
const app = express();
// 传入 express 的路由
app.use(autoRouter(new express.Router()));

app.listen('8888', () => {
    console.log(`server is running on port 8888`);
});
  • 在根目录中创建控制器目录 control, 创建控制器文件
const {Post, Controller} = require('night-decorator/decorator');
 // 公共前缀
@Controller('/demo')
class Test {
    // 当前url(Post 请求)
    // 请求支持 Post,Get,Put,Delete,Use(请求拦截时使用)方式)
    @Post('/sayHello') 
    sayHello(req, res) {
        res.send('hello world');
    }
}

module.exports = Test;
  • 在根目录中创建控制器目录 interceptor, 创建拦截器文件(选用)
    (1) 将装饰器放置在类上
const {Interceptor} = require('night-decorator/decorator');
 // 要拦截的前缀
@Interceptor("/demo")
class Test {
    // 必须指定为 init 函数
    init(req, res, next) {
        
        ... // 拦截处理
        
        next();
    }
}

module.exports = Test;

(2) 将装饰器放置在方法上

const {Interceptor} = require('night-decorator/decorator');
class Test {
    @Interceptor("/demo")
    // 方法可随意命名
    say(req, res, next) {
        
        ... // 拦截处理
        
        next();
    }
}

module.exports = Test;
请求地址为:
http://localhost:8888/demo/sayHello (Post 请求)