Gurpreet’s response is accurate, but I think I would add a few things. I know Rails pretty well, but I’m just learning node.js. while it’s true that you can write blocking (synchronous) or non-blocking (asynchronous) code in either language, Ruby is primarily a blocking language while Javascript is primarily non-blocking. As an example, both languages have relatively simple statements to open a file and read the contents of the file:
[Open file statement]
[Read file contents statement]
By default, if you run this in Ruby, you will get what you expect. It will open the file, then read its contents. Javascript won’t. It will issue the command to the operating system to open the file, then attempt to read the contents whether the file has finished opening or not. In javascript, you have to program the second statement as a function callback to the first statement.
You can write this asynchronously in Ruby, but that’s not the default. Simlarly, there’s are opensync and readsync functions in the javascript fs library which will operate synchronously, but you have to consciously use them.
Therefore, I still find node.js easier to use for asynchronous chaining. However, it would not meet my needs for an overall web application development framework. It is nowhere near as strong as rails (e.g., routing in node.js is much more work), even with frameworks such as express.js and templating engines. The other thing you have to watch is that there is absolutely no concurrency in node.js and you wouldn’t want to use it for heavy calculations. Rails also has much broader support for all kinds of things through gems. The npm library (the node.js equivalent) is nowhere close to being as robust and it is, again, a pain. Managing dependencies with the Ruby bundler is way easier than node.js. Convention is much more established in Rails, where node.js requires configuration.
My goal is to be able to use the two together (I’m not close to that yet). I would like to do web application development in Rails and use node.js for Ajax calls, particularly straightforward calls such as basic create, update, and delete operations and things like web socket pushing of information in json format.
With respect to web sockets, I don’t work with it much because support on Internet Explorer and Android is relatively recent and older versions of both browsers are still in use with a considerable number of users. My applications also typically don’t have a need for that type of push communication. I can tell you that node.js does have fairly robust support through socket.IO. The nice thing about socket.IO is that it kind of abstracts the bidirectional communication issue. It tests for websocket support. If it doesn’t exist, it uses older polling methods. You don’t really have to worry about it. To be honest, I haven’t really pursued web socket support in Ruby so I’m not sure what the options are or how complicated it is.
sorry if this was a little long, but I hope it answers your question.