node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »




Motivation for the module is to provide simple and consistent structure to controllers handling CREATE, READ, UPDATE, DELETE and LIST operations to resources and their subresources.

Build Status

Example controller = "test";
exports.subresources = {
    'subroute': require('./subroute')
exports.before = function(req, res, next) {
  if(req.params.test_id) {
    Tests.load(req.params.test_id, function(error, test) {
      if(test) {
        req.test = test;
        return next();
      } else {
        return next(error || new Error("test "+req.params.test_id+" not found"));
  } else {
    return next();
}; = function(req, res, next) {
exports.create = function(req, res, next) {
  Tests.create(req.body, function(err, test) {
    if(err) {
      return next(err);
    } else {

And to use the controllers:

var express = require('express')
  , crudl = require('express-crudl');
var app = express();
app.set('controller path', __dirname + '/controllers/');
// Will mount all the controllers to app and print the routes with verbose:true 
crudl(app, {verbose: true});

For an example directory structure for controllers see test/controllers


Only has the one method for loading and mounting the routes, express-crudl(app, options);

options available are: verbose controller_path

Functions in controllers

.before(req, res, next)

Middleware that is executed before the routes and before subresources.

.error(error, req, res, next)

Error handler for the route, if you want to have controller specific error handler.

.create(req, res, next)

The function executed for CREATE operation, ie POST /name

.read(req, res, next)

The function executed for READ operation, ie GET /name/:name_id

.update(req, res, next)

The function executed for UPDATE operation, ie PUT /name/:name_id

.del(req, res, next)

The function executed for DELETE operation, ie DELETE /name/:name_id

.list(req, res, next)

The function executed for LIST operation, ie GET /name

Variables in controllers


Object mapping the subresources in name:module pairs {'name': require('./name')}


prefix this controller under this path, exports.prefix = '/resource'; = 'sub'; maps the controller to '/resource/:resource_id/sub';


overrides the name of the controller, by default the file/directory name is used.


options are .set(key, value) to the app created for handling the routes.


Inspired by express-mvc