Bricks.js is an advanced modular web framework built on Node.js. Bricks.js is very flexible. It can be used as a standalone static webserver, a basic routing framework, a multi-level apache-like routing system, as well as being modular enough to have the capability to completely switch out its routing engine.

Installing


    $ npm install bricks

Source

https://github.com/JerrySievert/bricks

Super Basic Usage

Change directories into the directory that you wish to server files from:


    $ bricks

Usage:


    Usage: bricks [--help] [--port port] [--ipaddr ipaddr] [--path path] [--log log]
        --port port     [default 8080]
        --ipaddr ipaddr [default 0.0.0.0]
        --path path     [default "."]
        --log log       [default none]

Basic Usage


    var bricks = require('bricks');
    var appServer = new bricks.appserver();

    appServer.addRoute("/static/.+", appServer.plugins.filehandler, { basedir: "./static" });
    appServer.addRoute(".+", appServer.plugins.fourohfour);
    var server = appServer.createServer();

    server.listen(3000);

Routes

Routing in bricks is based on String matches and truth values. A regular expression may be passed, as well as a function that can determine whether or not the route should be executed.

The routersimplified:


    if (typeof(route) === 'function') {
        var match = route(path);
        if (match) {
            return true;
        }
    } else {
        if ((typeof(route) === 'string') && path.match(route)) {
            return true;
        }
    }

    return false;

Multi-level Routing

Bricks contains four levels of routes. Each of these routing levels can be executed separately and with different sets of rules. This allows for great flexibility when dealing with request manipulation, content, final content manipulation, and accounting.

Built-in Plugins

There are plugins that are built-in to bricks that cover basic usage. These plugins are light-weight and loaded as part of the application server. The plugins accept various options for configuration.

Error Handling

Bricks has a robust error handling system based on events. This allows for errors to be handled in a very flexible manner.