Today during my presentation at JSConf, I showed that RxJS is not only about the browser. RxJS can be used anywhere JavaScript is available. To showcase that, the webserver I used for my dictionary suggest sample, was entirely written in JavaScript, using node.js as the engine.

Attached to this post are the Rx bindings for node.js. With them you can use Rx to write asynchronous webservers. E.g. the Hello World sample from the homepage of the node.js project can be rewritten as follows:

var sys = require("sys");
var http = require('./rx_http');
var serverData = http.createServer();serverData.Delay(2000).Subscribe(function(details)
{
    details.response.writeHead(200, {
'Content-Type': 'text/html' });
    details.response.write(
"Hello World");
    details.response.end();
});
serverData.server.listen(8000);
sys.puts(
'Server running at http://127.0.0.1:8000/');

of course, this is just a simple hello world. With operators like SelectMany and the bindings to all the file system operators, we can write great asynchronous webservers, but that is for a future post. Please let me know if you like these bindings. I’ll try to keep them up-to-date as both Rx.JS and node.js development continue.

To use these bindings, copy rx.js from the official Rx download and add the files from this zip to the same directory.