Choosing a RESTful API node.js framework: koa vs loopback vs hapi
5 May 2016
We want to choose an API framework that has the following features:
- runs in node.js
- is API only (no oldschool MVC client side stuff, please. The website is a separate React project)
- has an ORM / database framework & supports transactions
- widely used and robust
- ideally has Typescript definitions
UPDATE 2017: I would strongly look into Adonis.js now if I were to do this again. Or perhaps Scala if I wanted a server that is typed and functional.
The options
First we go to http://nodeframework.com/ to see the options with a lot of github stars. We ignore the full MVC client frameworks:
Name · Stars · Comment
ORMs
Since Loopback is the only framework with an ORM let's look at general ORMs in node.js. Sequelize is the biggest Javascript ORM| but has mixed reviews. It does have TS definitions though. Knex has good reviews but is just a SQL query generator.
Comments from Reddit searches
- Koa has the smallest code. It was started by TJ Holowaychuk, the creator of Express.js. Express was sold to Strongloop (the creators of Loopback.js) who did nothing with it (it was maintained solely by Doug Wilson). It's not stable yet.
- People like Hapi. And it's maintained by Walmart so it's stable.
- Can't find many people with opinions on Loopback. It seems fast to code, but tightly coupled to the database model magically. Every route needs a database model. And people don't seem to like its opinionated convention over configuration style.
- Loopback has a steep learning curve because it has so many features.
- Loopback's ORM documentation has inaccuracies.
Conclusion
Loopback seems to have everything we need but I can't find any posts by anyone actually using it. And there are lots of posts about Hapi and everyone likes it - there are zero complaints. Thus I think it would be best to start with Hapi & Sequelize. If there are too many difficulties we could switch to Loopback.