Neat project! To echo what everyone else is saying, thanks for putting this out there.
I am curious as to what most HNers think of doing server side development in JS. It's obviously the flavor of the month, but I have yet to see the appeal. JS is certainly not a bad language, but it seems a lot more tedious than, say, ruby. The nesting of callbacks, the lack of built in OO infrastructure (given that most of us are trained with class based inheritance), the many quirks associated with making the language accessible to nonprogrammers. Am I missing something? Is there a really good reason to use JS on the server?
I use railway.js in production for a social bookmarking tool. I come from a rails background but a Rails API has some up and downs. I wanted to try node and have been very impressed. I use railway.js to serve up the iOS API (private beta) and the public beta website. It serves 800 reqs/min on a shared m1.small with one process and I've had no issues with it at all.
It plays a lot more smoothly with MongoDB and I find it far simpler to hook into more modern functionality with Websockets and client side JS rendering. I had a few issues with jugglingdb (which I forked and fixed) and it's all going smoothly.
I still use Rails for some sites but Node and railway.js let me bootstrap the whole API on MongoDB in a few days and get very acceptable performance.
The main reason Node.js is gaining popularity is because it is blazing fast, scales very well due to its IO + event driven architecture and it has the best support for websockets (see socket.io).
On the flip side, code can be hard to maintain and you need to be more disciplined so that you can read the code later otherwise it becomes a callback spaghetti. Doing everything through callbacks also requires a mental shift.
Like with everything in life, there are pros and cons and tradeoffs. So choose wisely :).
node.js isn't really that fast for traditional apps, but if you were to compare, it's pretty much on levels of nginx and it's actually slower serving static files. only in few cases node.js shows its power, i.e; real-time apps/games. i wouldn't build any full-blown websites in node.js. only a certain piece on the site i'd do it in node, like a widget or something.
Yep, you shouldn't be using node to serve static files anyway. This is something a reverse proxy such as nginx should do. Node can then be used to serve either as a pure API (serving json with express is the easiest way) for a webapp or render the webpages.
I agree about the CDN, even though for us performance is not so critical we need to use a CDN (yet). I didn't know node-http-proxy but it sounds interesting I'll check it out.
I agree. I would do the same but I couldn't find any examples of doing this on the web. One could potentially use Redis or a AMQP as a middleman to integrate node.js's push with a Rails app. If I get sometime on the weekend I would like to try this.
Perhaps I'm missing something but how is this a matter of opinion? If one wanted to avoid callbacks, which were the OC's original issue with node, one would break up the callback spaghetti into distinct, possibly prototyped objects, and glue them together with node's events. How is that any more difficult to maintain than, say, Python classes? If anything, I personally like the ability to choose the coding style with JS in this case, e.g. callbacks are great for quick prototyping when you can't be bothered to organize everything properly from the get-go.
In a language like Ruby or Python by using Fibers or Co-Routines(Greenlets), one can get benefit of non-blocking IO at the same time avoiding code spaghetti.
Gevent in python for example is pretty popular and similar is the case with Em-synchony in Ruby.
I have used callback objects but really that is not even close to what one can achieve with Fibers or Greenlets.
As silly as it sounds, one of my favorite aspects of Node is how ridiculously portable and modular it is. NPM makes everything a breeze, and (thanks to support from Microsoft) it actually allows easy development on Windows. I realize plenty of languages have their own package managers, but NPM is fantastic.
The callback aspect definitely requires more discipline, but I'm glad that I've learned it.
Nested callbacks naturally allows for non-blocking code, which leads to higher request capacity.
In, say, Ruby, you've got EventMachine for something equivalent but it's definitely "bolted" on to the language. Python has Twisted, with which I have no personal experience. In PHP, there are really no options.
If it's about higher request capacity, PHP scales horizontally with its share nothing, no application server architecture. I'm not advocating, just sayin'.
The Node / EventMachine / Twisted version of nonblocking IO is built on the Reactor Pattern. The common use case is to minimize IO delay. Whenever there is IO, a NodeJS script will cheerfully continue execution of other code, whereas in PHP and other purely synchronous languages, the script would block while waiting for the result. In practice, this has more use cases than just IO, of course. For example, one can send heavy computations to background processes and execute other code while waiting for the result.
So back to the original point, yes, writing nested callbacks can be more difficult to decipher than "flat" code, but the results may very well be worthwhile if you are looking to squeeze maximum performance out of your hardware.
I think the sweet spot for this kind of thing is when doing websockets. For a "normal" site, Rails is fine; it does a ton out of the box, and I like the language more than Javascript. However, the websocket story with Rails is not as clear as with something like Node, Erlang, or Go. This is worth repeating:
May be not as much clear. But Ruby world has plenty of options for Websocket as well. I have built production Websocket server on top of Goliath and Faye and it works like a charm.
Yeah, it's not like it's impossible with Ruby, but especially compared to a system like Erlang - to my way of thinking - it can start to look a bit clunky when you try and get lots of pieces talking to one another if, say, most of the rest of the application is in Rails. Or at least that's my impression, maybe I'm wrong?
I daresay you seem to have wrong impression. Having Rails app for typical web stuff and Eventmachine (em-synchrony) + faye stuff for realtime things work pretty well in actual usage. I can wrap DB calls, memcache/redis, SMTP connections etc inside my event loop and can achieve near same performance as a Node app.
The alternative of using node.js for everything sounds good but I am not really sure, how good node and its web frameworks are for building typical CRUD applications. Rails really solves building database backed applications problem pretty well.
I receive some kind of request in a Rails controller. I need to send, as a consequence, a notification via the web socket. How does it get from point A to point B? In Erlang, it's all likely to be quite contained and fast, and not involve writing anything to external queueing software, and to boot, it's all going to happen in the same unix process, rather than having one process that's the Rails server, and another that's the eventmachine server.
I don't know Node.js and how you'd handle sending messages from point A to point B, but I'd be interested in hearing some opinions.
Nested callbacks in JS means functions are first class members of the language..
...
thus
...
Functional programming is possible in JS..
...
thus
...
You can create beautiful abstractions with your code.
> It's a fact that you can create functional abstractions in JavaScript.
This is basically just restating "Javascript has first-class functions."
While first-class functions are nice, it's only the barest tip of the iceberg when it comes to what's needed for true functional programming. When you add more and stronger assumptions to your functions and types - referential transparency, static typing, immutable data structures - you get more and more back in functional expressive power and the tools that make it possible: memoization, concurrency, tail recursion, lazy evaluation, pattern matching, and so on.
The less assumptions you allow in the language, the more these powerful functional techniques and abstractions simply won't be possible. You still stand to gain from a modular, functional style, but you will have to go back to working around the inherently imperative language in most cases.
I am curious as to what most HNers think of doing server side development in JS. It's obviously the flavor of the month, but I have yet to see the appeal. JS is certainly not a bad language, but it seems a lot more tedious than, say, ruby. The nesting of callbacks, the lack of built in OO infrastructure (given that most of us are trained with class based inheritance), the many quirks associated with making the language accessible to nonprogrammers. Am I missing something? Is there a really good reason to use JS on the server?