0

I am starting work on an existing Node/Express/Mongoose project -- I am currently going through the code and trying to understand how it works. The Express routes are being generated dynamically, that is to say there are functions that set up the routes -- the http method, the path to resource, the Express app, etc are passed into those functions as parameters and the routes are constructed at runtime. There are many nested functions -- it's a complex project -- but it all ends up with the line

app[method](path, requireAuthentication, requireAdminAuthentication, validateRequestBody, done);

which sets up the route.

Is there any way to debug a route after it's been constructed? That is to say, if I wanted to put some debug() statements in the POST route for '/widgets', but that route doesn't exist anywhere in the code, and in fact doesn't exist at all until after the app starts, where do I put the statement?

Cerulean
  • 5,543
  • 9
  • 59
  • 111

1 Answers1

0

Well, you can use the DevTools and can get into the Sources tab and then press CTRL+O and then if you start typing the file name (which contains your dynamic routes) you can find it listed over there, just open it and set the breakpoint(s) where ever it is required.

Hope this helps!

David R
  • 14,711
  • 7
  • 54
  • 72
  • Thanks. Forgive me if I'm not getting it -- I'm new to the entire MEEN stack and Node itself -- but will these dynamic routes be added to the file that set them up (when viewed in DevTools)? When I open that file in Sources I only see the code that already exists in that file, i.e. what was on disk originally, not the dynamically added routes (which wouldn't have names in any case). – Cerulean Jul 18 '17 at 15:34