Hierarchical Router for Express.js
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.md
index.js
package.json

README.md

express-tree

Hierarchical (almost-declarative) routing for express.

Plant

npm i express-tree --save

var express = require('express');
require('express-tree');

var app = express();

Pluck

app.tree({
    '': function(req, res) {          // => app.get('/', ...)
        res.send('hello forest.')
    },
    login: 'login',                   // => res.render('login');
    account: {
        '': 'account/index',          // => /account
        register: 'account/register', // => /account/register
        settings: [ logged, 'account/settings' ],  // middleware works too!
    },
    // POST, PUT, and DELETE works like this. Not recommended, though.
    'POST login': passport.authenticate('local', { 
        successRedirect: '/',
        failureRedirect: '/login'
    })
});