node package manager


Enhancing urls for express.js.

Enhancing urls for express.js.


With this module you can name used urls and call them by name in the template.


urls = require('urls');

Set urls:

Set urls like you set them without this module

  { pattern: "/", view: routes.index, name: "index" },
  { pattern: "/api/user", view: user.list, name: "user", methods: ['get', 'post', 'put', 'delete'] },
  ], app);

*You have to pass the 'app' object so urls.js can move the urls and create dinamic helper.

Use in templates

Use url names in templates (jade example)

 p url from urls.js module #{ url("index") }

If you are using handlebars the HTML code will look something like:

  <a href="{{ url 'index' }}">home page</a>

You can send params like this (user:id):

  <a href="{{ url 'users/' }}0035262">aleksansrenko</a>