I gave an overview presentation on Node.js and Express.js at the OpenWest conference last week with one of my development team leads. You can view it here. I have been writing some simple Node applications and have really seen the power and potential of this platform. I felt so strongly that this was going to become a popular platform that I wanted to share what I had learned at this developer conference.
Many companies have found Node.js to be an ideal platform for developing their internal or customer applications. One example is PayPal. They decided to create a pilot project to evaluate Node vs an exising enterprise application built on Java. The pilot ended up far exceeding everyone's expectations: less than half the amount of code with only a couple developers vs 12 for the Java code base. They found it was easier read and maintain and it create clean boundaries between the UI, the app logic and the backend services. As of 2014, they had over 20 Node.js projects underway. In fact, they even made some of their code open source.
Many other companies have had success with Node: Walmart, LinkedIn, Yahoo, ebay, Uber, Dow Jones, New York Times and Capital One.
Node is fantastic for any application that needs to be real-time or is very I/O centric. It can be used for queuing to a database, such as for real-time analytics. Plus, it has a built-in web server, so it can be used as a server-side proxy like nginx. Node is also ideal for prototyping and creating APIs on top of object stores like MongoDB.
That doesn't mean Node works for all server apps. CPU-intensive apps do not perform well with the event-driven, non-blocking model. Also, it can be better to use something like Django or Rails when front ending a relational database.
Node's architecture is very modular. Modules allow the developer to easily bring in external functionality. Modules can export variables, functions and object. And when building a Node application, modules make it easy to modularize your code.
There are three main types of modules:
One of the most popular modules on NPM is Express.js. Express is a very popular web application framework that provides a robust base set of features for web and mobile apps. It gives you:
With Express, you can all use a variety of middleware to extend application functionality. You can use middleware for authentication, validation, data parsing, session management and more. Middleware review requests before they get sent to a specific route.
Express supports a number of View engines. Jade is the native templating engine. (Personally, I love Jade and used it to build this website.) Handlebars, Swig and EJS are other templating engines that can be used with Express.
The biggest problem with Node and Express are getting into complex callback procedures. However, new tools are becoming available with Promises and Generators. One NPM module called promise makes it easy to use promises. Similarly, there are a number of NPM available generators.
The number of dev tools that work with Node are phenomenal. Many tools for developers leverage Node, so even if you don't use Node for your server, you can use it for development. Examples include:
Node and Express provide a new platform for the next generation web applications. Both have become widely popular and should stay around for quite a while.