resource-tree /


A useful separation of lookup (URL parsing) and resources for implementing a HTTP server.

Installation: npm install resource-tree

Small example:

var resource_tree = require('resource-tree');

var root = {
    // Assuming "example.js" exists in the same directory as this script
    'example.js': new resource_tree.FileResource(require('path').join(__dirname, 'example.js'))

resource_tree.createServer(root).listen(8080, "");

console.log("Now you can GET");
console.log("Everything else is properly handled as 404 (Not Found) or 405 (Method Not Allowed)");

See example-fileresource.js and example-custom-resource.js for slightly more.