Source

resource-tree /

Filename Size Date modified Message
26 B
12 B
1.3 KB
498 B
935 B
3.6 KB
1.5 KB
609 B
781 B
1.7 KB
1.3 KB
964 B
526 B
532 B
620 B
672 B
1.4 KB
3.0 KB
146 B
946 B
568 B

resource-tree

A useful separation of lookup (URL parsing/routing) 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, "127.0.0.1");

console.log("Now you can GET http://127.0.0.1:8080/example.js");
console.log("Everything else is properly handled as 404 (Not Found) or 405 (Method Not Allowed)");

Examples by use-case: