Skip to content

Instantly share code, notes, and snippets.

@thejones
Created November 12, 2018 14:09
Show Gist options
  • Save thejones/dab4976d89cf2f9ba9204e9663e570f6 to your computer and use it in GitHub Desktop.
Save thejones/dab4976d89cf2f9ba9204e9663e570f6 to your computer and use it in GitHub Desktop.
Save express routes to file (express-list-endpoints)
const listEndpoints = require('express-list-endpoints')
var app = express();
//express setup
//then list them
// This is quick and dirty (no error probably cannot be run more than once correctly)
fs.mkdir(__dirname + "/tmp/", { recursive: true }, (err) => {
fs.writeFile(__dirname + "/tmp/routes.json", JSON.stringify(listEndpoints(app), null, 2), { flag: 'wx' }, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment