Skip to content

Instantly share code, notes, and snippets.

@way2datta
Created November 22, 2018 04:27
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 way2datta/a8c7fdb90d6f5bab445f8c801e09d136 to your computer and use it in GitHub Desktop.
Save way2datta/a8c7fdb90d6f5bab445f8c801e09d136 to your computer and use it in GitHub Desktop.
List down endpoints urls and http verbs that was built by using Node + Express
const express = require('express');
import routes from './routes/rest-api';
const app = express();
const port = 3000;
const hostUrl = "http://localhost:3000"
app.use('/', routes);
routes.stack.forEach(function (element) {
console.log(getHttpVerb(element.route) + " " + hostUrl + element.route.path);
});
function getHttpVerb(route) {
if (route.methods.delete) {
return "HTTP DELETE";
}
if (route.methods.post) {
return "HTTP POST ";
}
if (route.methods.put) {
return "HTTP PUT ";
}
return "HTTP GET ";
}
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment