Node Web frameworks comparison: Express, hapi and Sails
- select the contributor at the end of the page -
Choosing the right Web framework for your projects can be a daunting task. Lucky for you, we've put together a quick guide on three of the most popular picks for node including Express, hapi and Sails. We'll take a look at the pros and cons of each, along with when you should and shouldn't use them. But first, a quick recap on node.
For those who might not be familiar, node is a powerful, event-driven platform and it’s increasingly becoming the go-to technology for both startups and the enterprise (it's often used for building Web applications). Nearly two billion node libraries are downloaded every month -- keeping up with this blisteringly fast progression can be difficult. While node has the capabilities to build a Web application from scratch, many Web application frameworks have popped up over the years that provide several benefits, like reducing the time it takes to build custom applications. Now, let's take a look when you might want to use these.
Express was Created in 2009 by TJ Holowaychuk, one of the former maintainers of the node project. It was built on top of another node Web framework called connect, and provides a very minimal foundation for you to build your application. Middleware, first or third-party developed packages, are used to add additional functionality.
As one of the longest running and most successful node projects, Express has a large community. With a simple and to-the-point API, it’s easy to get a basic Web application up and running. The fact that Express has been in development since 2009 means that most of its wrinkles have been ironed out, and you can depend on development to be consistent and non-breaking.
Being so minimal, Express doesn’t provide infrastructure to scale to medium- or large-scale projects. As your project grows, the amount of code being written beyond the framework may become bloated and difficult to maintain. Your team will end up re-inventing the wheel multiple times to overcome Express’s growing pains. And relying on so many third-party middleware packages for additional functionality can cause your application to be brittle and sensitive to incompatibilities.
When to use it
Express is a good choice for small to medium projects when you need to find developers who have experience with the framework. If your company or team is new to node, Express experience won’t be hard to find. If you expect your project to be maintained by a large team, or need real-time communication, Express isn’t the best choice.
Learn how to build RESTful Web services with Express.
hapi was created in 2011 by Eran Hammer from his work at Walmart Labs. It was originally written on top of Express, but quickly removed any dependency before version 1.0. hapi’s philosophy can be boiled down to “configuration over code,” which allows more focus on building application logic than it does on infrastructure. It provides an opinionated and rich foundation to build applications and includes a configuration pattern that reduces the possibility of errors.
hapi was developed by an experienced team that ran the framework in a production environment. Common use cases and needs are baked into the framework, which means less work for developers to get a stable, secure and working application deployed. The structure of hapi applications make it easy to work in a team, and the approach to adding business logic means your application will be maintainable as it grows.
The community around hapi is one of the smaller ones, especially considering the amount of companies using hapi in production. Despite Walmart open sourcing hapi nearly from the beginning, it hasn’t caught on as significantly as the other two frameworks.
When to use it
hapi is a good choice for projects of any size, and boasts a proven track record of providing a very dependable framework to support applications under heavy load. It may be difficult to find developers with a depth of hapi experience, but it’s an approachable framework for newcomers and reinforces node best practices. hapi is built for large projects and large teams, so there should be no issues with scaling.
Learn how to build Web applications with hapi.
Sails was created in 2012 by Mike McNeil as an encapsulation of express and socket.io. Named after Ruby on Rails, it follows the same MVC pattern and includes a command line generator for data modeling. It also adds an opinionated application structure to facilitate development.
Sails’s MVC pattern is tried and true and is commonly understood by Web developers (a quick ramp up to being productive). The similarities with Ruby on Rails are extremely attractive to developers with the relevant experience. The comprehensive Sails package includes pipeline management, Websockets, ORM, security policies and everything else you might possibly need, so reaching outside of the Sails project will be very uncommon.
Sails has the weakest documentation of the three frameworks. The size and complexity of what it offers makes the API documentation seem obtuse and unorganized. Basic tutorials or “Getting Started” guides are sorely needed. Moreover, Sails makes opinionated assumptions about your application and how it will be structured, which may end up being a hindrance as your application matures and needs more customizing.
When to use it
Sails is a good choice for small to medium projects that closely fit the MVC model and need real-time functionality. The pool of Sails developers may not be that large, but developers with Rails or express experience should have no trouble ramping up.
Learn API development with Sails.