Skip to content

Instantly share code, notes, and snippets.

@iddar
Created August 29, 2019 13:53

Revisions

  1. iddar renamed this gist Aug 29, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. iddar created this gist Aug 29, 2019.
    19 changes: 19 additions & 0 deletions write_express_routes
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    function getTrue(obj) {
    return Object.keys(obj).filter(el => obj[el])
    }


    const fs = require('fs')
    const stream = fs.createWriteStream("routes_file.txt")

    stream.once('open', function(fd) {
    api.stack.forEach(function(r){
    if (r.route && r.route.path){
    let line = `[${getTrue(r.route.methods).join(',')}]: ${r.route.path}`
    stream.write(line + '\n')
    console.log(line)
    }
    })

    stream.end();
    })