node.jsexpressexpress-router

How to access path route from request object using express router


I working on route level access, need to get path from route object like /history/:id. If I am using route.path or route.get('path') both not working.

route: Route {
    path: '/history/:id',
    stack: [ [Layer], [Layer] ],
    methods: { get: true }
}

Solution

  • if (typeof req.route === 'object') {
       console.log(req.route.path);
     }