Introducing the Best 10 Node.js Frameworks for 2019 and 2020
Sam
Posted on August 23, 2019
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:
The scalability and robustness of the framework
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.
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.
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.
Posted on August 23, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.