Skip to content

A express package to list all registered endpoints and its verbs.

License

Notifications You must be signed in to change notification settings

laendoor/express-routes

Repository files navigation

Express Routes

Build Status Dependencies Coverage Status Maintainability

NPM

This is a fork from AlbertoFdzM/express-list-endpoints repository.

Express endpoint parser to retrieve a list of the passed router with the set verbs.

Installation

npm install express-routes

Examples of use

Print Routes

const { printRoutes } = require('express-routes');

const app = require('express')();

app.route('/')
  .all(function(req, res) { /* Handle request */ })
  .get(function(req, res) { /* Handle request */ })
  .post(function(req, res) { /* Handle request */ });

app.route('/about')
  .get(function(req, res) { /* Handle request */ });

printRoutes(app);
// It omits the 'all' verbs.
/*
GET   /
POST  /
GET   /about
*/

Get Endpoints

const { getEndpoints } = require('express-routes');

const app = require('express')();

app.route('/')
  .all(function(req, res) { /* Handle request */ })
  .get(function(req, res) { /* Handle request */ })
  .post(function(req, res) { /* Handle request */ });

app.route('/about')
  .get(function(req, res) { /* Handle request */ });

console.log(listEndpoints(app));
/* It omits the 'all' verbs.
[{
    path: '/',
    methods: ['GET', 'POST']
  },
  {
    path: '/about',
    methods: ['GET']
}]
*/

Arguments

app - Express app or router instance

Your router instance (router) or your app instance (app).

Note: Pay attention that before call this script the router or app must have the endpoints registered due to detect them.

license

MIT

About

A express package to list all registered endpoints and its verbs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •