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.
- There’s a steep asynchronus learning curve
- The Node.js project and its libraries move fast, and you have to keep up
- The community support is amazing and very active
- Some of the libraries can save you a ton of time
- Server stuff is often easier to handle
- You can “cut corners” on requests easier
- Interacting with other websites is simple
- You can MVC all you want
- NPM is awesome
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.
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.
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.
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.
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)
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.
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)
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
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
I’m sure many of you have heard about the new server side javascript project called node.js. I’ve been using myself to build full stack dynamic websites and find it a very nice environment to create a dynamic website. When I first started out I had no idea what sort of way one should create an MVC style framework with node or what modules would help me to achieve the model, view, controller ideal. Heres my stack:
- Node.js (http://nodejs.org/) of course
- NPM (http://npmjs.org/) to easily install packages for node.
- Express (http://expressjs.com/) – a very nice web development framework built on connect (allows “controllers”)
- Mongoose (http://mongoosejs.com/) – a solid orm for mongodb in node.js that just released a much improved version (allows “models”)
- Jade (http://jade-lang.com/) – a template engine for node that allows some cool shorthand (allows “views”)
- Other tools were used of course but those were the essentials.
The application directory looks something like this:
1 2 3 4 5 6 7 8 9 10 | /app-root /models /views /controllers /public /tests /scripts /logs /tmp app.js |
Inside the application I instantiate express, include my mongoose models and include my routes/controllers from the controllers directory at the bottom. Inside the controllers I call res.render to render the jade views and it all works very nicely. If people would like me to elaborate on this more let me know.
A huge shoutout and thank you to the LearnBoost guys (TJ Holowaychuk, Guillermo Rauch, Aaron Heckmann, and many more that aren’t associated with LearnBoost) who’ve made Node.js web application development a breeze.

