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

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

santypk4 profile image Sam Quinn Originally published at softwareontheroad.com on ・6 min read

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

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')
);

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 

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

Then to create a project

$ lb4 app

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!';
  }
}

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}`)
})

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);
});

👉 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();

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();

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);

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}!`))

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

Posted on by:

santypk4 profile

Sam Quinn

@santypk4

Node.js Developer, AWS Lover, JavaScript advocate, React.js is my friend.

Discussion

markdown guide
 

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.

 

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.

 

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)

 

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.

 

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

 

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)

 

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

 

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

 

Glad to see fastify on this list 👍

 

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!

 

I hope to be using fastify soon !!

 

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! 👯

 

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?

 

Loopback is at number 7 in this list.

 

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

 

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?

 

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.

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.

 

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

 

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.

 

Absolutely right , Node.js is a perfect platform to use right now, but however we cannot totally forget about PHP .I recently moved from PHP to Node.js and made an article to share my experience: hackernoon.com/nodejs-vs-php-which... Kindly go through it and choose yourself.

 

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.

 

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.

 

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

 

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

 

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