It seems more and more so that people are interested in building their applications in node.js yet there are few reviews on what it’s actually like to work with the framework. I’ve designed and am nearly finished building out all of the features of a full scale (user accounts etc) social news site in node. (www.exipe.com) Here are a few of the things I’ve found and maybe they can help you in your decision to go with node. I will choose to ignore the thing that people point to first: because its event oriented it can handle more concurrent users better. Lets assume that as true and talk about some things that less people are talking about.

  1. There’s a steep asynchronus learning curve
  2. Even though I’ve made many a javascript application before working on this project, including fooling around in node some, I found adapting to the asynchronous programming style a significant challenge. Every database interaction you do, every file system read or write, even http requests are asynchronous and need callbacks. This means that quite often if you want to do 10 different things for example you can end up with spaghetti code with 10 different scoping levels of indentation. As you learn and grow with the tools in node you learn that you can attach listeners to things and create separate functions to mitigate these problems and shortly after it almost feels natural.

  3. The Node.js project and its libraries move fast, and you have to keep up
  4. As many of you know node is a very new open source framework that has undergone many changes (some of which can break things) in the last few months. (since I started working with it on Exipe) This meant that I needed to be careful to notice what changed in the update and make sure I fixed anything that broke when updating. Some would ask “why don’t you just use the old version?” My response to that is the bug fixes and improvements are well worth the small changes in node. Another thing that happens is libraries such as mongoose (which we have been using to interact with our MongoDB database) undergo many changes as well. If I had any advice to give here it would be keep up with the latest going on in node and the packages/libraries you use because if you fall behind there may be no one willing to support an older version.

  5. The community support is amazing and very active
  6. Like many programmers I frequent sites like github, google groups and stackoverflow. Upon asking questions, posting comments or sharing bugs about anything node related on those sites I’ve found a response that was fast, cordial and most importantly … correct. This has made any headaches in dealing with such a new framework relatively painless because so many others are going through or working on the same issues. I think I even heard that the node github page is more active than the rails project page.

  7. Some of the libraries can save you a ton of time
  8. I found that one of the features I wanted in the site was a facebook login. While I’ve previously dealt with facebook connect in php and found it relatively painless there I expected something like that might be a headache in node. After finding the connect-auth library it turned into a piece of cake with a little monkey see monkey do thrown in from following the examples. I wanted to interact with S3 to store images and found a wonderful project called knox. Pretty much anything you can think of theres probably a tool that integrates with node that is of high quality and actively developed.

  9. Server stuff is often easier to handle
  10. Working on php applications I often remember having to learn the black magic of configuring apache to do what I wanted. While not rocket science it seemed to be overly difficult and finding easy to understand, accurate documentation was hard. In node, if you use it as the server things like changing the port you’re hosting it on is as easy as changing which number you tell it to listen on. (these things are often/can be internal to node)

  11. You can “cut corners” on requests easier
  12. It is fairly trivial to tell node to return a web request (say a user voting on a link) before interacting with the database, thus minimizing the time that the user is waiting for feedback. While I never got deep enough on a big project to want to do this with php, I’m not sure of how to do it off the top of my head.

  13. Interacting with other websites is simple
  14. Telling your webserver to go out, download a web page, parse it and return something of significance to you is very easy in node. Something I have found more challenging in other languages and frameworks. (while possible and very doable they don’t support it so directly as node does)

  15. You can MVC all you want
  16. In one of my previous posts I talk about a simple MVC setup with node.js. Similar to frameworks in other languages it is not only possible, but easy to set up and powerful

  17. NPM is awesome
  18. If you want to install/update any of the packages you are using for node it is always very easy to do so with a tool like NPM. A simple npm install whatever_package and bingo you have it, ready to go.

Hopefully this post has convinced some people to try out node for its active community/powerful tools and dissuaded some not intent on the extra learning/maintenance because that’s what I’ve found you’re probably in for. Whether node.js is the choice for you or not, I’ve found that the pros outweigh the cons in development of exipe and have loved working with the framework. Shameless plug: If you feel like checking out what a node.js website feels like head over to www.exipe.com and sign up for our beta coming in March.

For those of you from HackerNews waiting for me to open source the more specific/thorough example of a node MVC setup, worry not as its nearly done and I’ll share it soon

Be Sociable, Share!
 

23 Responses to What it’s like building a real website in Node.js

  1. Rahul says:

    This goes into my bookmark. Thank you very much for sharing. Looking forward to the open source project you mentioned. I am learning node.js myself and something like this would be immensely helpful.

    By the way, I really like your color combination. If you can make everything fit into the page so that one need not have to scroll, it will be perfect (only because it is a beta-signup page). Just m two cents though :)

  2. hitesh says:

    I just started my first site in node as well and agree with everything here (and wish I had this a week ago)

    Curious to hear what you think about flow control helpers like the async module? .

  3. hitesh says:

    My bad, I messed up the link to async.js.. That one should work.

  4. Rahul says:

    Oh could you also add some details about the server architecture please? I imagine you must have used S3 but in addition, can you also add other related details?

  5. admin says:

    @Rahul – we’re currently running on Amazon’s EC2 and will hopefully scale on that if we’re successful. I’ll post a blog post on that when I get a chance here if you want.

  6. Rahul says:

    @Travis: That would be great… I am sure there will be many other who will benefit from it. Thanks!

  7. Mark Loiseau says:

    Great insight, and Exipe looks good so far…

  8. Nice article. Can you say a word about deploying ? How do you deploy your application ? Do you use something like Capistrano or Vlad for the job ?

  9. 0101 says:

    Are you using any PaaS for Node? or you’ll be managing the server instances yourself?

  10. Danny Siu says:

    I found Q for Node.js tremendously helpful for doing sequencial tasks. I know it defies the the purpose of asynchronism and have to learn the CommonJS Promise primitives in order to use Q, but there are many cases where I need to perform a task given another task is finished.

    https://github.com/kriskowal/q

    — D

  11. Joan says:

    Great post, I agree with everything on it. NPM is the best package manager I’ve used in a framework. And hell, all the nodejs tools move very fast, it might be a pain to catch up sometimes, like the new Mongoose API.

    Regards,

  12. Jon Lim says:

    Great read!

    One of the things I was wondering is how did you handle the notification emails being sent through Exipe? Did you do that through Node.JS? I’d love to hear the process behind that.

  13. Kuroki Kaze says:

    Hello. I’ve translated your post for http://nodejs.ru and linked back to you. Hope you don’t mind :)

  14. droope says:

    sounds great!

  15. Just one note about #6: You can just use flush() in PHP to send the current buffer response early.

  16. johans says:

    Thanks for very useful insights.

    Callback “spaghetti” – sounds like Node could benefit from something like the new deferreds in jQuery.

    EC2 – are you running Node on port 80 for your site or do you use a proxy server like Nginx to route request to Node / S3 (static) etc?

  17. Exactly what I’ve been looking for!

    I finally have some down time, and what do I do (instead of play Portal 2… which is right in front of me)? I compile node.js and try to bust out some sort of MVC + couchdb website.

    :P

    Thanks again!

  18. > Telling your webserver to go out, download a web page, parse it and return something of significance to you is very easy in node.

    I imagine this is true especially if you have fetches contingent on other fetches, some of which may be done in parallel. I’ve used threading for this in the past but events would probably be cleaner because I wouldn’t have to manually split serial tasks into threads. A diamond dependency (not fetching a page twice if two threads lead to it) would also be easier to handle in a single thread, as would other things.

  19. Gregg says:

    Bad timing: “Firefox can’t establish a connection to the server at http://www.exipe.com.”

    ;)

  20. digitalpbk says:

    What about the lack of threads in node.js ? Does it affect performance ?

  21. TheOutlander says:

    Good article, thanks!

  22. You might like to try awssum instead of knox since it is more complete and actively maintained. Note: I’m the author of awssum so I’m biased, but these two statements are actually true. :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>