Allows for loading resources from a filesystem structure matching the URI


Load express routes (and params) automatically from a directory, where the path to each file corresponds to it's URL.

npm install express-resourceful
var express = require('express');
var resourceful = require('express-resourceful');
var app = require('express');
resourceful(app, 'resources'); // runs synchronously 
path to resourceurl

Each exported method that corresponds to an HTTP method will be added to the router/app.

exports.url = '/foo'; // *OPTIONAL* can be used to override the default url 
exports.get = function (reqres) {
  // GET handler... 
}; = function (reqres) {
  // POST handler... 

A single exported function can be used as a param handler. (where the param name is determined by the filename)

module.exports = function (reqresnextid) {
  // param handler 

Will scan the given dir (sychronously) for resource files and mount them to app. (which can either be a plain express app or an express.Router instance)

The optional prefix will be prepended onto the generated paths.

Any files found in the _params directory will be treated as param handlers.

NOTE: Resource files beginning with a : (ie: route params) will be mounted after static routes, to prevent a route like /users/new from being preempted by users/:user.