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

express-modulesroute

v1.0.2

Published

modules route

Readme

express-modulesroute

模块路由

介绍

开发程序的时候,常用的模式就是模块和模块各自分开,比如控制器,路由规则,模型等等,express-modulesroute可以自动读取各个模块中的路由,不需要把每个模块的路由放到单独的routes文件夹中,这样在开发和维护的时候,结构比较清晰,路由跟着模块走,容易维护。

目录结构

app // 可以自定义名字
  + modules // 可以自定义名字
    + ...
    + user // 可以自定义名字
      + ...
      + controllers // 控制器,路由的回调都放在这里执行,不是必须的
      + router // 不可以自定义名字
        + index.js // 不可以自定义名字

安装

$ npm install express-modulesroute

使用

在express项目中的主文件,以中间件的形式加入进来,如在app.js加入以下代码,因为是应用级中间件,所以不需要挂在到具体某个路径上,autoRoute接收一个参数,即模块路径,目录结构参考下面,因为我业务代码都写在app下面,不同的路由由不同的controller去处理

express的app.js路由默认是这样的:

app.use('/', index);
app.use('/users', users);

把上面那段代码替换成:

const modulesroute = require('express-modulesroute'); // 添加到文件头部
app.use(modulesroute(path.join(__dirname, 'app/modules'))); // 'app/modules'替换成自己程序模块的目录