0

For example, I have these routes:

router.get('/addUser',name="addUser");
router.post('/editUser',name="editUser");

Now I want set Name for these routes and Return All Routes With Name:

- Add User
- Edit User

How can I set a Name for each route and return all routes with Name in nodejs?

Ouroborus
  • 16,237
  • 4
  • 39
  • 62
kianoush dortaj
  • 411
  • 7
  • 24
  • did you want something like this? https://www.npmjs.com/package/named-routes – Karl L Jun 16 '20 at 05:24
  • @user9879287 i dint want to use the npm-package . iwant write code fir this – kianoush dortaj Jun 16 '20 at 06:01
  • can you give an idea how you want to use the names? – Karl L Jun 16 '20 at 06:06
  • If you don't want to use an additional package, you'd have to handle naming and searching yourself. To actually get a list of routes associated with an app, see https://stackoverflow.com/questions/14934452/how-to-get-all-registered-routes-in-express – Ouroborus Jun 16 '20 at 06:33
  • @Ouroborus i want to retrun all routes with name in for example return name . this link can not set the name – kianoush dortaj Jun 16 '20 at 06:38
  • Yes, that's why you'd have to manage naming and querying against them yourself. Routes don't have names on their own. They just have a path and a handler. (I see you're trying to set a name using a named parameter. If you're using something other than Express for routing, you should mention that.) – Ouroborus Jun 16 '20 at 06:45
  • @Ouroborus i want return route by name for using dynamic access level . – kianoush dortaj Jun 16 '20 at 07:46
  • Express routes don't have names. Are you using some other package? – Ouroborus Jun 17 '20 at 01:39
  • @Ouroborus no i'm not . i want to find a way for using this – kianoush dortaj Jun 17 '20 at 06:37
  • So you'll need to create a way to associate names with routes (possibly an object with the keys as the names and arrays of routes as the values) and then you'll need to create a way to search those names and retrieve the routes. – Ouroborus Jun 18 '20 at 08:47
  • @Ouroborus yes . i want to create a dynamic access level . ican find name of route and show that to use . – kianoush dortaj Jun 18 '20 at 08:54
  • Then you're going to have to write some code and, if you run into problems, we can help with troubleshooting. Stackoverflow isn't a code writing service. – Ouroborus Jun 18 '20 at 09:10

0 Answers0