Last active
October 17, 2020 22:40
-
-
Save fabiojwalter/7219e9313c27c4cccc8b93e5268dd886 to your computer and use it in GitHub Desktop.
NodeJS - List Routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
app.get("/apis", (req, res) => { | |
let get = app._router.stack.filter(r => r.route && r.route.methods.get).map(r => r.route.path); | |
let post = app._router.stack.filter(r => r.route && r.route.methods.post).map(r => r.route.path); | |
let put = app._router.stack.filter(r => r.route && r.route.methods.put).map(r => r.route.path); | |
let del = app._router.stack.filter(r => r.route && r.route.methods.del).map(r => r.route.path); | |
res.send({ "get": get, "post": post, "delete": del, "put": put}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment