In my backend app I am using express-promise-router
to manage my routes.
For example:
const express = require( 'express' );
const router = require( 'express-promise-router' )();
let app = express();
app.use( router.get( "/hc" , ( req,res,next )=> res.status( 200 ).send( "healthy!" ) ) );
I want to list all the routes in the backend app.
since I am using the express-promise-router
, I can't use the app._router.stack
Any suggestions?
CodePudding user response:
I've used the package express-list-endpoints in the past, worked great.
Usage:
const express = require("express");
const expressPromiseRouter = require("express-promise-router");
const listEndpoints = require("express-list-endpoints");
const app = express();
const router = expressPromiseRouter();
router.get("/hc", (req, res) => res.status(200).send("healthy!"));
app.use(router);
console.log(listEndpoints(app));
CodePudding user response:
You can use express-list-endpoints module for that:
const listEndpoints = require('express-list-endpoints');
let app = require('express')();
// ... app usage
console.log(listEndpoints(app));
Also, may you already seen these, but this can be useful later: