2

I need to avoid writing hardcoding URls in Node apps(code or views). Is there a package?

Now I write in Jade: a(href='/account/profile') Profile Profile url is hardcoded. I need something like this: a(href=links.accounts.profile()) Profile

It will be very useful when I will change URLs. I need to be able to change URLs just from a config file, not from all views...

dumitru
  • 379
  • 2
  • 10
  • Solution must work and for external, static files not just for app routes. For example, if I change host for static resources I need change just host in config/setup - not in all views! – dumitru Feb 10 '14 at 12:33

1 Answers1

0

You can use this package - reversable-router.

Example from their readme:

app.get('/admin/user/:id', 'admin.user.edit', function(req, res, next){
    //...
});

//.. and a helper in the view files:
url('admin.user.edit', {id: 2})
dark_ruby
  • 7,646
  • 7
  • 32
  • 57