DEV Community

Cover image for Introducing the Best 10 Node.js Frameworks for 2019 and 2020
Sam
Sam

Posted on • Originally published at softwareontheroad.com on

Introducing the Best 10 Node.js Frameworks for 2019 and 2020

Originally published at softwareontheroad.com

I’m so tired of reading articles claiming what is the best node.js framework based on biased opinions or sponsorships (yes, that’s a thing)

So here are the top node.js frameworks ranked by daily downloads, the data was taken from npmjs.com itself (sorry yarn).

What is a node.js framework?

How to choose a node.js framework for my application?

You have to consider mainly 2 things:

  1. The scalability and robustness of the framework

  2. If the development process is something you feel comfortable working with.

Regardless of scalability and robustness, every node.js web framework is built on top of the http module.

Some of these frameworks add too much … and that makes a huge impact on the server’s throughput.

In my opinion, working with a barebone framework like Express.js or Fastify.js is the best when the service you are developing is small in business logic but need to be highly scalable.

By the other hand, if you are developing a medium size application, it’s better to go with a framework that helps you have a clear structure like next.js or loopback.

There is no simple answer to the question, you better have a peek on how to declare API routes on every framework on this list and decide for yourself.

10. Adonis

Adonis.js is an MVC (Model-View-Controller) node.js framework capable of building an API Rest with JWT authentication and database access.

What’s is this framework about?

The good thing is that Adonis.js framework comes with a CLI to create the bootstrap for applications.

$ npm i -g @adonisjs/cli
$ adonis new adonis-tasks
$ adonis serve --dev
Enter fullscreen mode Exit fullscreen mode

The typical Adonis app has an MVC structure, that way you don’t waste time figuring out how you should structure your web server.

Some apps built with adonis can be found here.

👉 GET MORE ADVANCED NODE.JS DEVELOPMENT ARTICLES

Join the other 2,000+ savvy node.js developers who get article updates.

Email List Form

9. Feathers

Feather.js is a node.js framework promise to be a REST and realtime API layer for modern applications.

See what’s capable of!!

This is all the code you need to set-up your API REST + realtime WebSockets connection thanks to the socket.io plugin

const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const socketio = require('@feathersjs/socketio');

const memory = require('feathers-memory');

// Creates an Express compatible Feathers application
const app = express(feathers());

// Parse HTTP JSON bodies
app.use(express.json());
// Parse URL-encoded params
app.use(express.urlencoded({ extended: true }));
// Add REST API support
app.configure(express.rest());
// Configure Socket.io real-time APIs
app.configure(socketio());
// Register a messages service with pagination
app.use('/messages', memory({
  paginate: {
    default: 10,
    max: 25
  }
}));
// Register a nicer error handler than the default Express one
app.use(express.errorHandler());

// Add any new real-time connection to the `everybody` channel
app.on('connection', connection => app.channel('everybody').join(connection));
// Publish all events to the `everybody` channel
app.publish(data => app.channel('everybody'));

// Start the server
app.listen(3030).on('listening', () =>
  console.log('Feathers server listening on localhost:3030')
);
Enter fullscreen mode Exit fullscreen mode

Pretty sweet right?

Here are some apps built with feathers.js.

8. Sails

Sails.js Ye’ olde node.js framework

With 7 years of maturity, this is a battle-tested node.js web framework that you should definitively check out!

See it in action

Sails.js comes with a CLI tool to help you get started in just 4 steps

$ npm install sails -g
$ sails new test-project
$ cd test-project
$ sails lift 
Enter fullscreen mode Exit fullscreen mode

7. Loopback

Backed by IBM, Loopback.io is an enterprise-grade node.js framework, used by companies such as GoDaddy, Symantec, IBM itself.

They even offer Long-Term Support (LTS) for 18 months!

This framework comes with a CLI tool to scaffold your node.js server

$ npm i -g @loopback/cli

Enter fullscreen mode Exit fullscreen mode

Then to create a project

$ lb4 app
Enter fullscreen mode Exit fullscreen mode

Here is what an API route and controller looks like:

import {get} from '@loopback/rest';

export class HelloController {
  @get('/hello')
  hello(): string {
    return 'Hello world!';
  }
}
Enter fullscreen mode Exit fullscreen mode

6. Fastify

Fastify.io is a node.js framework that is designed to be the replacement of express.js with a 65% better performance.

Show me the code

// Require the framework and instantiate it
const fastify = require('fastify')({
  logger: true
})

// Declare a route
fastify.get('/', (request, reply) => {
  reply.send({ hello: 'world' })
})

// Run the server!
fastify.listen(3000, (err, address) => {
  if (err) throw err
  fastify.log.info(`server listening on ${address}`)
})
Enter fullscreen mode Exit fullscreen mode

And that’s it!

I love the simplicity and reminiscence to Express.js of Fastify.js, definitively is the framework to go if performance is an issue in your server.

5. Restify

Restify claims to be the future of Node.js Web Frameworks.

This framework is used in production by NPM, Netflix, Pinterest and Napster.

Code example

Setting up a Restify.js server is just as simple as this

const restify = require('restify');

function respond(req, res, next) {
  res.send('hello ' + req.params.name);
  next();
}

const server = restify.createServer();
server.get('/hello/:name', respond);
server.head('/hello/:name', respond);

server.listen(8080, function() {
  console.log('%s listening at %s', server.name, server.url);
});
Enter fullscreen mode Exit fullscreen mode

👉 GET MORE ADVANCED NODE.JS DEVELOPMENT ARTICLES

Join the other 2,000+ savvy node.js developers who get article updates.

Email List Form

4. Nest.js

A relatively new node.js framework, Nest.js has a similar architecture to Angular.io, so if you are familiar with that frontend framework, you'll find this one pretty easy to develop as well.

Example

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.setViewEngine('hbs');
  await app.listen(3000);
}
bootstrap();
Enter fullscreen mode Exit fullscreen mode

3. Hapi

One of the big 3 node.js frameworks, hapi.js has an ecosystem of libraries and plugins that makes the framework highly customizable.

Although I never used hapi.js on production, I’ve been using its validation library Joi.js for years.

Creating a server

A hapi.js webserver looks like this

const Hapi = require('@hapi/hapi');

const init = async () => {

  const server = Hapi.server({
      port: 3000,
      host: 'localhost'
  });

  await server.start();
  console.log('Server running on %s', server.info.uri);
};

init();
Enter fullscreen mode Exit fullscreen mode

2. Koa

Koa is a web framework designed by the team behind Express.js the most famous and used node.js framework.

Koa aims to be a smaller, more expressive, and more robust foundation for web applications and APIs than express.js.

Through leveraging generators Koa allows you to ditch callbacks and greatly increase error-handling.

Koa does not bundle any middleware within the core and provides an elegant suite of methods that make writing servers fast and enjoyable.

Example

const Koa = require('koa'); 
const app = new Koa(); 
app.use(async ctx => { 
  ctx.body = 'Hello World'; 
}); 
app.listen(3000);
Enter fullscreen mode Exit fullscreen mode

1. Express

Express.js is definitively the king of node.js frameworks, will reach the incredible mark of 2 million daily downloads by the end of 2019.

Despite being such an old framework, Express.js is actively maintained by the community and is used by big companies such as User, Mulesoft, IBM, and so on.

Example

Just add it to your node.js project

$ npm install express

Then declare some API routes

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Enter fullscreen mode Exit fullscreen mode

And that’s all you need to start using it!

Conclusion

There are tons of node.js frameworks out there, the best you can do is go and try them all ‘til you find the ones that suit your needs.

Personally, I prefer Express.js because, through these 6 years of node.js development, I build a strong knowledge of good architectural patterns, all based on trial and error.

But that doesn’t mean you have to do the same, here is all the secrets of a good express.js framework project.

Now tell me, what is your favorite node.js framework?

Send me a tweet to @santypk4, come on! I want to know what the people are using, I don’t want to fall behind!

👉 GET MORE ADVANCED NODE.JS DEVELOPMENT ARTICLES

Join the other 2,000+ savvy node.js developers who get article updates.

Email List Form

Latest comments (38)

Collapse
 
adegbengaagoro profile image
Agoro, Adegbenga. B

People who don't really know the inner workings of AdonisJS think it can be used exclusively for MVC apps only.

There is a slim version of AdonisJS that can be used to build out APIs and microservices, if Microservices are your thing.

Even though it favours SQL based databases, it is extensible enough for new additions and we have seen the community create packages that supports the use of mongodb and/or graphql.

The beauty of AdonisJS is it helps you get out of your own way, also you should check out the latest version, AdonisJS v5 which was re-written from the ground-up with support for Typescript

Collapse
 
lexiebkm profile image
Alexander B.K.

What about eggjs (eggjs.org) ?
Why is it very rarely mentioned in any articles on node frameworks ? Because it is made in China ?
A lot of people love Vue.js and Ant Design (Antd) which are essentially made by chinese guys, but tend to ignore this node framework.
I read from its official site that its design philosophy and goal are encouraging. However I just cannot get started on it before I am convinced that it has wide acceptance by community. Its Github star is quite impressive, but I suspect it's largely from developers in China.

Collapse
 
lexiebkm profile image
Alexander B.K.

I am currently learning Express, Feathers and Hapi in parallel. But your introduction of Fastify immediately trigger me to visit its site. The site says Fastify is inspired by Hapi and Express but offers better performance, so I should learn it too. Koa is interesting too.
Only after having sufficient skills in these "traditional" but fundamental frameworks, I can try modern frameworks like Total.js (totaljs.com/platform) that draws my attention too.

Collapse
 
navicsteinr profile image
Navicstein Rotciv

From my perspective, sails.js should be first before adonis because it's battle tested and has an efficient ORM much more simpler than others, its main advantage is its waterline and self validation actions, secondly, why's loopback not in the list?

Collapse
 
lexiebkm profile image
Alexander B.K.

Loopback is at number 7 in this list.

Collapse
 
santypk4 profile image
Sam

What is supporting the abstraction of async/await syntax ?
Generators and coroutines :D

Collapse
 
adegbengaagoro profile image
Agoro, Adegbenga. B

I strongly believe AdonisJS should be like No. 1 on this list. Good thing though is it made the list.

As far as I am concerned, it's my No. 1 for all times when it comes to JavaScript Frameworks

Collapse
 
ozzythegiant profile image
Oziel Perez

I agree. Not sure how it stacks up against Hapi but this definitely needs to be #1 or at least a #2 behind Express. My approach to learning frameworks is to have one monolithic framework and one micro framework learned per programming language. For PHP, I use Slim and Laravel. For Python, I use Flask and Django. For Java, I use Spark and Spring Boot. In Node.js so far I've only learned Express, but I would say it's like Flask and Slim, it's a micro framework, but for when I'm needing to save time and have something that includes all of the essentials, I would take a look at Adonis.

Collapse
 
avidcoder123 profile image
avidcoder123

It is healthy to learn a microframework but I feel like Express can't really be compared to Flask. Flask does all the basics for you like cookies, sessions, and templating engine but Express doesn't. Express is a bit too flexible; you shouldn't have to worry about such rudimentary things when making servers.

Thread Thread
 
ozzythegiant profile image
Oziel Perez

We'll I put them side by side because both of them require you to patch in your own libraries for some things, like ORM. A full framework will include most, if not all things that are commonly used to build apps

Collapse
 
noway profile image
Ilia

Curious: what are the benefits of Adonis over Express.js? Would you consider switching existing Express projects to Adonis, or would it only make sense to start new projects from Adonis?

Collapse
 
chillysource profile image
Nicolas Cacace

One of the benefits often cited about Node is that it allows you to code in a single language - Javascript.
I see this COMPLETELY flawed understanding of programing languages ALL THE TIME.
The two implementations of front-end Javascript programing in the browser and Node are like chalk and cheese.
....So when I see Adonis JS offering a Laravel-Like environment my radar suddenly 'goes off'
...and when I see that Adonis only offers support for Databases which fundamentally were designed for Multi-Threaded environments I have to say that my suspicions are in the process of being confirmed; you can know any language back to front yet COMPLETELY fail to grasp WHY it's designed the way it is at a fundamental level. (I see it all the time)

...It's like the many C programmers I witnessed in the the 90s adopting C++ yet continuing to write procedural code completely failing to grasp the OOP paradigm.

I would look at one of these for Node...
blog.logrocket.com/forget-express-...
...and if you like Adonis because you're used to Laravel OR like its MVC structure because you have a huge project then GO WITH LARAVEL.....Symfony | Zend (Which are even stricter MVC Frameworks for PHP)
... but it'll will cost you more in Hardware

What you can do is split your tasks that require High demand and delegate those for a Node environment. Intelligent design can save you lots of Money in the long run. Technology is always about Pros and Cons. There is seldom a magic bullet that solves all problems.

Fish are designed for swimming, Animals for walking and birds for flying.
Pick one - Laravel or Node. Two COMPLETELY different paradigms.

Thread Thread
 
avidcoder123 profile image
avidcoder123

Your reasoning is flawed. We aren't using Adonis because we want a carbon copy of Laravel, we are developers who write JavaScript who want an option better than the most popular garbage like express.js

Thread Thread
 
faithfulojebiyi profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
Faithful Ojebiyi

You dare not call a framework that has 5 times the stars of Adonjis Garbage.. Seems like you just started programing or you have no idea what you're talking about.

If you're too lazy to set up your project then use a framework like Adonis... Don't come here bashing Express because you have a hard time setting it up. Apparently, a good developer should be Framework agnostic.

Thread Thread
 
avidcoder123 profile image
avidcoder123

Measuring Github Stars only shows popularity, not quality.
Also, there is a difference between being lazy and being efficient. Isn't driving a car lazy if you can just walk?
The problem about Express is that gluing modules that are not created to work together will only cause headaches. Also Express is poorly designed. Trying to use async/await will cause memory leaks and/or crash your app, the routing is not deterministic, and it is full of bottlenecks. Just search up Netflix's experiences with Express and you will see what I mean.

Thread Thread
 
avidcoder123 profile image
avidcoder123
Thread Thread
 
faithfulojebiyi profile image
Faithful Ojebiyi • Edited

You probably didn't do your research well... And the Author of the Netflix post admitted to using Express API wrongly... Which caused their issues.. they fixed their codebase and the issue was gone.. PS that was express V1 Express is on V5...
stackoverflow.com/questions/273045...

How do async await cause memory leaks... You're talking like an inexperienced engineer. .. You only have memory leaks in a badly designed application.

Thread Thread
 
avidcoder123 profile image
avidcoder123

Express doen't know how to handle async/await. If an error is thrown inside an async handler, instead of the error being handled correctly it throws an UnhandlesPromiseRejectionError in Node 15+ and can cause memory leaks in below versions

Thread Thread
 
cupliz profile image
Iyan Cupliz

I've tried almost all framework (express,koa,nest,adonis,feathers,hapi,etc) and i think Express wins from them all by simplicity. I'm using express with/out Typescript for 5 years and it works very well with no issue. If you face UnhandlesPromiseRejectionError, you might not use try/catch in the first place. Yes, by default it doesn't handle that error. If you face some problems in Express, belive me it's not the framework fault, sometimes its dev lack of knowledges.

And for Romain Lanz article, mostly not true and he tends to drop Express because he is one of the Adonisjs contributor.

Collapse
 
michi profile image
Michael Z • Edited

AdonisJs is battery included, comes with db setup, mail, mvc, testing utlities, you name it. It lets you focus on writing the application, so you don't have to focus much about building the architecture around it.

Thread Thread
 
noway profile image
Ilia

Thanks a lot, that makes sense. I prefer to compile those modules together myself, that tend to achieve maximum flexibility and gives you a better time if there appeared to be a better alternative on the market which needs to be included vs relying on framework devs to bring the support and define the migration path for it. Got very burnt on that with Sails and their ORM. Seems like Adonis is a good alternative to Sails in that regard, so if I need to pick ease of initial setup as a requirement for another project, Adonis would be a good candidate.

Thread Thread
 
avidcoder123 profile image
avidcoder123

Flexibility is truly very important in Node.js, I agree. But it is very powerful to have a default, and AdonisJS doesn't stop you from installing new packages if you want to.

Collapse
 
santypk4 profile image
Sam

It’s such a great and easy to learn framework :)

Collapse
 
lexiebkm profile image
Alexander B.K.

Especially for developers who have been using Laravel. Adonis is inspired by Laravel, hence it is called Laravel of Node.js.
However, I am not sure about its maturity/stability, so I postpone to learn it further. But when it gets wide acceptance from the community, I will use it. Currently, I am considering Hapi.js to be my option.

Collapse
 
kaythinks profile image
kaythinks

AdonisJS is definitely in the top 3 most used NodeJS MVC Framework.

Collapse
 
santypk4 profile image
Sam

It’s awesome to see so much community around AdonisJS :)

Collapse
 
rumkin profile image
Paul Rumkin • Edited

Take a look at Plant. It's a WebAPI based framework. And it seems like it's the only which supports HTTP/2 pushes. It's transport agnostic what means you can deliver requests via HTTP(S), WebSocket, WebRTC, etc. Also it works in browser without compilation/browserification due to its' WebAPI compatibility and transport agnosticism, though you can develop your server using text editor and DevTools for debugging.

I wrote it and ready to answer questions.

P.S. You place too much advertisement into the post. It's too unfriendly to the readers.

Collapse
 
noway profile image
Ilia

Do you know how does it compare performance wise versus Fastify? Having a benchmark would be nice. (My use case does benefit from performance, so I'm choosing between frameworks mainly on performance + availability of extra plugins and DevEx)

Collapse
 
rumkin profile image
Paul Rumkin • Edited

On hello world test its' performance was about express'. But on my machine koa was always behind express and on fastify's benchmarks it's not. Need a verification.

Super high performance has never been the main goal of the current development iteration, I've just been holding it on acceptable level before API became stable. Currently I'm working on improvement which should make Plant faster than others with extra deep optimizations, but it's a piece of work. Not sure if it will be done very soon.

Collapse
 
santypk4 profile image
Sam

Seems like an amazing framework, I’ll try it :)

Collapse
 
arizonatribe profile image
David Nunez

Also, Polka should probably get a mention too, considering how dominant it is in benchmark tests vs others, and how highly it ranked in user satisfaction (see Eran Hammer's article on Node framework dominance in 2019)

Collapse
 
noway profile image
Ilia

How does it stack up against Fastify performance wise? Would be nice to see it in the leaderboard here: fastify.io/benchmarks/

Collapse
 
santypk4 profile image
Sam

Thanks for sharing about Polka, seems like a pretty sweet framework to work with!

Collapse
 
arizonatribe profile image
David Nunez

Nest doesn't belong on this list. It gets out of control really quickly and suddenly you realize you've landed in an old school ASP MVC or Zend app where new developers have to spend a month ramping up to figure out where everything is and groking the abstraction layers. Nest might be okay for small apps, but it'll get out of control and then you're back to the "memorization driven development" that we used to lean on in old school monoliths.

Collapse
 
roblav96 profile image
Robert Laverty • Edited

Glad to see fastify on this list 👍

Collapse
 
roblav96 profile image
Robert Laverty • Edited

If y'all want something more express.js like and really wanna go barbones, I recommend checking out Polka: A micro web server so fast, it'll make you dance! 👯

Collapse
 
noway profile image
Ilia

For my specific use case (pure rest api with a mobile client) it looks to be the perfect alternative. Actually thinking of switching from Koa+debug.js!

Collapse
 
santypk4 profile image
Sam

I hope to be using fastify soon !!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.