Skip to content

Instantly share code, notes, and snippets.

@fabiojwalter
Last active October 17, 2020 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiojwalter/7219e9313c27c4cccc8b93e5268dd886 to your computer and use it in GitHub Desktop.
Save fabiojwalter/7219e9313c27c4cccc8b93e5268dd886 to your computer and use it in GitHub Desktop.
NodeJS - List Routes
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