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-pathfinder

v1.1.0

Published

A module for collecting all of the paths registered by the Express Router

Readme

express-pathfinder

A module that provides a simple Method - URI views of all the registered routes in an Express application.

What does it do?

express-pathfinder takes advantage of Express's app._router.stack object and iterates over the registered routes to get the attached method and the related URI.

Why not just use app._router.stack?

The main problem that I have found with app._router.stack is that, if you mount router modules onto paths, it does not provide the path the router was mounted on.

For example, if I have a user.js and a staff.js in my routes folder, and they both have something like:

router.get("/login", function(req, res, next){
  res.render("loginview", {/* some data */})
})

And I included and mounted them in my app.js like so:

var users = require("./routes/users.js")
var staff = require("./routes/staff.js")

app.use("/users", users)
app.use("/staff", staff)

And then used app._router.stack and iterated over the results to get the method and uri of all the routes, I would end up having two GET routes with the same path of /login, becuase it has not included the path that the route files were mounted on.

express-pathfinder takes care of this problem.

Installation

npm install express-pathfinder

Usage

Usage is quite simple for this module. Inside the the main application file (app.js for example) add the following:

var pathfinder = require('express-pathfinder')

var routes = pathfinder(app._router.stack, "GET")

The above code will retireve all of the paths registered with the method GET.

If I wanted to get both GET and POST routes, for example, I could change the second line to:

var routes = pathfinder(app._router.stack, ["GET", "POST"])

Providing an array of methods instead of a string.

The second, methods, parameter is an optional parameter. If no specific methods are provided, by string or array, then the function to the default settings of using all of the methods supported by the http module.

Note: The pathfinder function must be used after mounting the router modules to their respective paths.

Example Data Returned

[
  { method: "GET", path: "/" },
  { method: "GET", path: "/users" },
  { method: "GET", path: "/users/:user_id/profile" },
  { method: "GET", path: "/users/login" },
  { method: "POST", path: "/users/login" },
  { method: "GET", path: "/articles/:id" },
]

Function and Parameters

pathfinder(routes, methods) - returns Array

| Parameter | Expected Type | Examples | Description | Default | |---|---|---|---|---| | routes | Object | app._router.stack| The object that contains the information about the routes registered in the Express application | N/A | | methods (optional)| StringArray | "GET"["GET", "POST"] | A string, or an array of strings, outlining the method(s) that should be looked for when returning routes | require('http').METHODS |