Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

What can/can't node.js do?

I'm having some confusion about node.js. Can it do everything rails can do? Could build something like youtube? What are it's limits?

1 Answer

The short answer would be, in theory, node.js can do everything Ruby on Rails can do, but that's not the whole picture.

First of all, node.js is much lower level (without using some packages) than Rails, and the amount of extra code you'd need to write to achieve the same thing could be daunting. Thankfully, there are some excellent packages out there (look into Express or Sails) to make things easier.

Also, certain frameworks are better at some things than other things. node.js's strong point is also its weakness — its asynchronous nature makes it better at pure I/O operations, which makes it great for providing APIs.

However, any kind of computationally intense operation may block the thread and you lose any benefits you get from async — in fact, all the users will end up waiting until that computation is finished. A threaded Rails app with background workers would work much better in this scenario.

This is an oversimplification but it's important.

Take a look here to see some of the companies using node.js and how they're using it. I'm going to select a couple of highlights and list them here:

  • LinkedIn uses node for its mobile software stack
  • The New York Times mobile web is powered by node
  • PayPal seems to have moved their web services completely (or will in the near future) to node
  • eBay seems to be using node more and more
  • Goupon has switched to node.js from Rails

To answer your question about YouTube — could you build something like that in node? Yes. Should you? Probably not. YouTube is huge and I won't even pretend I understand its architecture, but I don know it involves a lot more than a couple of node clusters.

node.js is a fantastic and powerful technology but it's not the silver bullet — there is no such thing. There are times when it's appropriate and/or convenient and those are the times when it's useful.

I use node.js often but that's mostly because I love JavaScript and know the language fairly well. I use it for console apps, web apps, mobile servers, but there are times when the project requirements simply don't fit what node does best.

Whenever you start a project, it's best to outline all the requirements, figure out what the bottlenecks will be, how computationally intensive it will be, how much I/O will it be doing and so on. Only after that can you say if node (or any other technology) is a good fit. Sometimes, you'll find that certain projects will need a couple of technologies. Using node.js alongside Rails is not unheard of.

James Barnett
James Barnett
39,199 Points

The way I think of it is Ruby is to Node as Rails is to Express