Node JS Bindings for RxJS

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' });
"Hello World");
'Server running at');

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.

Comments (9)
  1. Demis Bellot says:

    I really like how you are focusing on adding support for node.js as I think its a very interesting project with a bright future (maybe someone at MS can support the windows port?).

    But, I’m not liking this added un-predictable wrapper API around his server API. The request and response are now also hidden on the callback under the details object. This effectively forces users to read docs to find out how to use Rx node.js wrappers, which unless they have a natural desire to Rx-things won’t bother.

    rx_http.createServer(); != http.createServer();

    it’s more like http.createRxWrappedServer();

    //If its possible I would consider the following API if possible

    var server = http.createServer();

    $Rx(server).Delay(2000).Subscribe(function(req,res) {

     res.writeHead(200, {‘Content-Type’: ‘text/plain’});

     res.end(‘Hello Worldn’);



    On a side note, how much of Rx is open-source? Are the JavaScript libs all open source? I’ve read that the server libs are freely available but not open-source, is this still the case?

  2. Hi Demis,

    sorry for the late reply, the JSConf was pretty much 24/7 🙂 I’d love to see a node.js windows port, will talk to our Open Source lab to give them a nice gentle push in that direction 🙂

    I’ll see if I can change the createServer api to become a bit nicer. The subscribe won’t work as there is too many operators that need to deal with a single value per source such as Zip, Join, ForkJoin etc…

    Rx has its own license which can be found on the Rx project page. Like Rx, the license is also under continuous development, so give feedback on the forums if there is anything blocking you from using it so we can make a stronger argument for potential changes. The nodejs wrappers are a sample that you should feel free to do with whatever you want.


  3. Demis Bellot says:

    Hi Jeff,

    No worries I understand jsconf was busy as I manage to catch most of the tweets (its a shame I couldn’t make it). Thanks for the pointer to the forums I will drop a line there.

    Unfortunately I only develop cross-platform applications + frameworks so I wont be interested in adopting or using a technology that also can’t be made to work (or is developed) by Mono. As Rx seems like a tremendous amount of effort and the mono team seems to have their hands full, they probably won’t be attempting their own implementation in the foreseeable future. It’s a pity you guys aren’t in Scott Gu’s team as they have had a more inclination to share their technology in recent times which I believe helps spur broader adoption. My basic thought process is I can choose to use the niceties provided by the Rx fx but then I will limit the usefulness and applicability of my software – which I don’t/won’t like doing.

    Anyways back to the client. I understand that you may need a single argument so I guess that’s a good as argument as any too keep that part of the API the same 🙂

    Where you can, I would try to be as intuitive and non-invasive as possible. Maybe you can modify the http prototype directly and apply the Rx *extension methods* on top of it, otheriwse you can do it explicitly with $RxIt(server) as seen in the example. If you can provide a superset API then I think more people will use it as it lowers the barrier to entry and they won’t need to ‘port’ their source code over to use it as much. This lets developers ‘opt-in’ to use an elegant Rx solution when they need to.

    Apart from that the only other consideration I think too keep in mind is to provide a very ‘fast implementation’ as this is something that most node.js care very deeply about (as I’m sure you already know).

    Anyways you look like you’re doing great work in this area, I will be looking forward to seeing the development of these libraries in future. The more examples showcasing the elegance and usefulness of the Rx fx I think will be just as important as the rich API.

    – Demis

  4. Hi Demis,

    What is blocking Rx from running on mono? Rx doesn’t use p/invokes or COM interop so we were assuming it would fine. Let me know if there is anything we need to change to get it running.

    Yup aware of perf requirements of mono, enjoyed Ryan’s talk on the subject at jsconf. Will try to make the sample a little nicer this week.

    Thanks for your feedback!


  5. Demis Bellot says:

    Hey Jeff,

    I think it’s a legal problem, the licence seems very restrictive and seems to forbid distribution of it. The mono crew are more than happy to announce any new shiny tech that comes their way (e.g. Silverlight toolkit, ASP.NET MVC, etc). When there is some cool like PLINQ there are usually efforts to implement it. Otherwise there are libraries like WPF which are just too big and require too much effort that they’ll probably never be implemented which i sadly how I think Rx will go unless its donated. Unfortunately there’s not a whimper on usage of Rx on Mono and with the license the way it is, I think it will need an official statement from Microsoft for it to ever be considered to run on that platform.

    I hear the codeplex foundation now provides an opportunity for Microsoft to be able to freely share some of their tech under a viable legal framework, maybe its worth exploring this option.

    Anyway the RxJs stuff looks pretty safe and am looking forward to your contributions in this area.

  6. Mike says:


    The zip file no longer works.

    Is this binding no longer supported?

  7. Bill says:

    Bump.  It will be great if the link to can be fixed.  If there's a reason the file's no longer available it will be helpful (in a pedagogoical sense) to know why.

Comments are closed.

Skip to main content