title: get all registered route in nodejs
body: <p>i want to return all registered route in my project.</p>
  <p>i use this code for retur nall routes :</p>
  <pre><code>const app = require(&quot;express&quot;);
  let routers = app._router.stack
    .filter((r) =&gt; r.route)
    .map((r) =&gt; {
      return {
        method: Object.keys(r.route.methods)[0].toUpperCase(),
        path: r.route.path,
      };
    });
  </code></pre>
  <p>but it not worked and show me this error :</p>
  <blockquote>
  <p>(node:13092) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'stack' of undefined</p>
  </blockquote>
  <p><strong>Edit :</strong></p>
  <p>my routes :</p>
  <pre><code>    const express=require('express');
  const router=express.Router();
  const roleRouter=require('./role');
  const userRouter=require('./user');
  const managerRouter=require('./manager');
  const accessRouter=require('./access');
  const settingRouter=require('./setting');
  
  
  router.use('/role',roleRouter);
  
  router.use('/user',userRouter);
  
  router.use('/manager',managerRouter);
  
  router.use('/access',accessRouter);
  
  router.use('/setting',settingRouter);
  
  module.exports=router;
  </code></pre>
  <p>and use that in the main js file :</p>
  <pre><code>   app.use(require(&quot;./routes/index&quot;));
  </code></pre>
  <p><strong>how can i return all routes in my projects ???</strong></p>