Important
This package only works for express 4.* versions. It's not compatible with express 5 yet.
Express endpoint parser to retrieve a list of the passed router with the set verbs.
const express = require("express");
const expressListEndpoints = require("express-list-endpoints");
let app = express();
app
.route("/")
.all(function namedMiddleware(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
});
const endpoints = expressListEndpoints(app);
console.log(endpoints);
/* It omits 'all' handlers.
[
{
path: '/',
methods: [ 'GET', 'POST' ],
middlewares: [ 'namedMiddleware', 'anonymous', 'anonymous' ]
},
{
path: '/about',
methods: [ 'GET' ],
middlewares: [ 'anonymous' ]
}
]
*/
import express from "express";
import expressListEndpoints from "express-list-endpoints";
let app = express();
app
.route("/")
.all(function namedMiddleware(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
});
const endpoints = expressListEndpoints(app);
console.log(endpoints);
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.
Running test:
npm test
Express List Endpoints is MIT licensed.