Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Named routes for Express.
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.travis.yml
README.md
index.js
package.json
test.js

README.md

Pathfinder

Simple named routes for Express.

Build Status

Deprecation Warning

The following methods will print deprecation messages when used as extending the express app variable is error prone and doesn't really provide a better interface, especially when calling routes from controllers (req.app.p('login') is a lot more verbose than simply requiring path-finder).

app.p(pathname)
app.addPath(pathname, path)

Usage

  1. Install via npm

    $ npm install path-finder
    
  2. Extend your Express app

    var express = require('express');
    var app = express();
    var pathFinder = require('path-finder');
    pathFinder.extend(app);
  3. Profit

    // Standard Express routing does not change
    app.get('/users', function(){...})
    
    // Passing in a name stores the path
    app.get('/home', 'home', function(){...})
    app.post('/user/:id', 'user', function(){...});
    
    // Paths can be accessed via
    pathFinder.path('home');           //-> '/home'
    pathFinder.path('user', {id: 10}); //-> '/user/10'
    
    // Passing in additional options adds them to the query string
    pathFinder.path('home', {p: 1});   //-> '/home?p=1'
    
    // Ad-hoc paths can also be defined
    pathFinder.addPath('promotions', '/promotions');
    pathFinder.path('promotions');     //-> '/promotions'

    A p method is also made available to views

    a(href=p('promotions'))
      | View our promotions
    

Development

Clone the repo

$ git clone git@github.com:davidcornu/path-finder.git

Install dependencies

$ npm install

Run the tests

$ npm test
Something went wrong with that request. Please try again.