Getting Started with Node.js Web App Development

Getting Started with Node.js Web App Development

NodeJS logo

Affinity Bridge is primarily a Drupal shop. We've found Drupal to be a great tool for many of the problems we've been solving. Namely collaborating with non-profits and progressive organizations to build successful web sites. Whether it be data intensive mapping projects, group based collaboration systems, or just a simple brochure site, Drupal is a great tool for many jobs.

Recently we decided to explore some other technologies to get a taste for what is off of "Drupal Island". One technology that many of us here have been keeping an eye on is Node.js.

The culture at Affinity Bridge invites innovation and self-education so that our team members can learn and challenge ourselves. We began looking for a project to work on so that we could learn more about Node.js. After some brainstorming we decided on a simple web app project.

Overview of Node.js

As noted on the project homepage, Node.js is "a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications." Leveraging Chrome's Javascript runtime V8 means that Node.js applications are written in Javascript. One benefit of this is that Javascript is one of the most popular programming languages so the potential developer community is large. Another benefit is less context switching between server-side and client-side programming. Node.js applications are easy to write. Just a few lines of Javascript can accomplish great feats. Node.js applications are fast. The included http server benchmarks peak at over 3800 requests/second on my OSX laptop. Node.js is scalable. The included Cluster API allows the ability to create a cluster of node processes over all available server cores. And by adding multiple machines it's been shown that node can hit 250k concurrent connections.

Introducing My2Cents

My2Cents is about connecting Canadian citizens to their elected representatives. It creates embeddable iframe widgets that grab the users location and pulls in info on that areas local elected representatives. It then replaces phone numbers with a "Call Now" button. Users can click the button and be directly connected with the representatives office via their browser.

We're open sourcing and releasing My2Cents in its very early stages. It's still very rough around the edges. Development is ongoing. For anyone interested in contributing please feel free to file issues and open pull requests.

Tools used

We followed the small pieces loosely joined philosophy. There are many great Javascript tools and API's available and we looked to piece a number of these together in a way that aligned with our goals.

A few months ago I came across the Open North Represent API and began work on a Represent Node.js module. I liked the idea of an API giving access to elected representatives. Having previous experience using the Twilio API I thought these could be a great match.

Twilio takes the complexity out of both placing/receiving phone calls and sending/receiving text messages over the web.

We chose Express as the web framework based on its popularity, simplicity, and ease of use.

We hosted our app on Heroku, again for it's simplicity and ease of deployment. Heroku also has a healthy add ons ecosystem.

A number of remaining tools used include:

  • Git for version control (Heroku dependency)
  • Jade for templating
  • Stylus for CSS preprocessing
  • Redis for session storage
  • MongoDB for campaign storage
  • Mongoose, a MongoDB ORM
  • Passport for authentication
  • Jake, like Make, but for Javascript
  • Make for running tests. (I hope to use only Make or Jake but ran into issues getting Mocha to run with Jake)
  • Mocha for testing
  • JSHint for code linting
  • Docco for documentation

Our experience building the app

We assigned two developers to this project. I surprised even myself that after one day of pair programming we had a working prototype that sent the users location to the Represent API, received representative information, and displayed a widget with a functioning "Call Now" Twilio button.

We have since had another full day of pair programming where we added user authentication, campaign creation and storage, and fixed up a few bugs. Throughout the development process we found developing with node to be very quick, intuitive, and enjoyable.

Affinity Bridge & Node.js

We're excited about Node.js and it's role in the future of the web. It's a great tool for applications that might not suit Drupal. We will keep experimenting and learning more.

If you're interested in developing and app and think that Node.js might be a good tool for the job please get in touch.