Fork me on GitHub

Common Node

Synchronous CommonJS compatibility layer for Node.js

Overview

Common Node implements a number of CommonJS proposals on top of Node.js using node-fibers. By emulating multi-threading within a single process, you can now:

Common Node versus plain Node

var httpclient = require('httpclient');
exports.app = function() {
  return { 
    status : 200, 
    headers : {}, 
    body: new httpclient
      .HttpClient({
        url: 'http://google.com'
      }).finish().body 
  };
}









var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {});
  http.get({
    host: 'google.com', 
    port: 80, path: '/'}, 
      function(r) {
        var chunks = [];
        r.on('data', function (chunk) {
          chunks.push(chunk);
        });
        r.on('end', function() {
          chunks.forEach(
            function(chunk) {
              res.write(chunk);
            });
          res.end();
        });
    });
}).listen(8080);

Get Started

Install Common Node, check out more examples or read the API reference.

For more background on each module, browse the CommonJS wiki pages: