Skip to content

Bram-dc/express-list-endpoints-2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express List Endpoints 2

NPM

Original package by albertofdzm

Express endpoint parser to retrieve a list of the routes and methods with their given request handlers.

Example of use

Warning: In contrast to the original package, this package does not merge endpoints which are initialized in different chains.

const listEndpoints = require('express-list-endpoints-2')
const app = require('express')();

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

app.route('/')
    .all(function namedMiddleware2(req, res) {
        // Handle request
    })
    .post((req, res) => {
        // Handle request
    });

app.route('/about')
    .get((req, res) => {
        // Handle request
    })

console.log(listEndpoints(app))

/* It omits the 'all' verbs.
[
  {
    path: '/',
    methods: [ 'GET', 'POST' ],
    middlewares: [
      [Function: namedMiddleware],
      [Function (anonymous)],
      [Function (anonymous)]
    ]
  },
  {
    path: '/',
    methods: [ 'POST' ],
    middlewares: [ [Function: namedMiddleware2], [Function (anonymous)] ]
  },
  {
    path: '/about',
    methods: [ 'GET' ],
    middlewares: [ [Function (anonymous)] ]
  }
]
*/

Arguments

app - Express app or router instance

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

Note: Pay attention that before you call this script the router or app must have the endpoints registered first.

License

Express List Endpoints 2 is MIT licensed.

About

A modified version of express-list-endpoints

Resources

License

Stars

Watchers

Forks

Packages

No packages published