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

trailxpress

v1.5.4

Published

Parse your Express API and find various route details like HTTP method, paths and function bodies

Readme


🚀 TrailXpress

Parse your Express API and extract various route details like HTTP methods, paths, middleware names, and function bodies.

Features

Extract Routes: Automatically extracts route details from your Express application.
Middleware Detection: Retrieves middleware names along with route details.
Supports Different Function Types: Works with inline, arrow, and named functions.
Swagger Documentation: Generates Swagger docs automatically.
Postman Collection Generation: Exports API routes as a Postman collection.
CLI Support: Use TrailXpress directly from the command line.


Installation

Install TrailXpress via npm:

npm install trailxpress

To use it globally for CLI:

npm install -g trailxpress

Usage

1️⃣ Programmatic Usage

Include TrailXpress in your Node.js project and extract routes from an Express API file.

//app.js
const express = require('express');
const userRoutes = require('./routes/user.routes.js');
const productRoutes = require('./routes/product.routes.js');
const { isAuthenticated } = require('./middlewares/auth.middleware');

const app = express();
const router=express.Router();

app.use(express.json());
app.use('/api/users', userRoutes);
app.use('/api/products', productRoutes);
app.get('/', (req, res) => {
  res.send('Welcome to the API');
});

//index.js
const { getRoutes } = require('./src/generators/routesGenerator.js');
console.log(getRoutes('/path/to/app.js'));

Sample Output

[
  {
    method: 'GET',
    path: '/',
    middlewares: [],
    handlerName: '',
    handlerCode: "(req, res) => {\n  res.send('Welcome to the API');\n}"
  },
  {
    method: 'POST',
    path: '/api/users/',
    middlewares: [ 'isAuthenticated' ],
    handlerName: 'createUser',
    handlerCode: '(req, res) => {\n' +
      '  const {\n' +
      '    name,\n' +
      '    email\n' +
      '  } = req.body;\n' +
      '  res.status(201).json({\n' +
      '    id: Date.now(),\n' +
      '    name,\n' +
      '    email\n' +
      '  });\n' +
      '}'
  },
  {
    method: 'GET',
    path: '/api/products/:id',
    middlewares: [],
    handlerName: 'getProductById',
    handlerCode: '(req, res) => {\n' +
      '  const {\n' +
      '    id\n' +
      '  } = req.params;\n' +
      '  res.json({\n' +
      '    id,\n' +
      "    name: 'Sample Product'\n" +
      '  });\n' +
      '}'
  }
]

2️⃣ CLI Usage

You can use TrailXpress from the command line without writing any code.

Extract routes from an API file

trailxpress extract -f api.js

Generate Swagger documentation

trailxpress swagger -f api.js -s

-s saves the output to a file (swagger.json).

Generate Postman Collection

trailxpress postman -f api.js -c config.json -s

-c config.json allows passing custom configuration (see below).


Config File (config.json)

Instead of passing multiple CLI flags, you can specify settings in a config file.

{
  "name": "My API",
  "description": "Automatically generated API documentation",
  "baseUrl": "https://api.example.com",
  "version": "2.1.0",
  "save": true
}

Programmatic API - Function Parameters

getRoutes Function

| Parameter | Type | Default | Description | |------------|----------|----------|------------| | filePath | string | Required | Path to the Express API file. | | methods | array | [] | (Optional) Array of HTTP methods to filter. |

generateSwagger Function

| Parameter | Type | Default | Description | |-----------|----------|----------|------------| | routes | array | Required | Array of extracted route details. | | save | boolean | false | (Optional) Save Swagger doc. | | format | string | "JSON" | (Optional) "YAML" for YAML format. |

Example Usage

const { generateSwagger, getRoutes } = require('trailxpress');

const apiFilePath = 'path/to/your/api/file.js';
const routes = getRoutes(apiFilePath);
const swaggerDocs = generateSwagger(routes,true,'yaml');

console.log(swaggerDocs);

generatePostmanCollection Function

| Parameter | Type | Default | Description | |------------|----------|----------|------------| | routes | array | Required | Extracted route details. | | options | object | {} | (Optional) Custom Postman collection options. |

Example Usage

const { generatePostmanCollection, getRoutes } = require('trailxpress');

const routes = getRoutes('path/to/api.js');

const options = {
  name: 'My API Collection',
  description: 'Postman collection for my API',
  baseUrl: 'https://api.example.com'
};

const postmanCollection = generatePostmanCollection(routes, options);
console.log(JSON.stringify(postmanCollection, null, 2));

Issues & Feature Requests

If you encounter any issues or have feature requests, open an issue on GitHub.


License

MIT