An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
Why you should drop ExpressJS in 2021
Express is currently, and for many years, the de-facto library in the Node.js ecosystem. When you are looking for any tutorial to learn Node, Express is presented and taught to people.
In the latest State of JS survey, Express was TOP 1 for all categories.
Despite all of this, Express is not a great technology, and you should have stopped using it since 2015.
--
It is unmaintained
Express has not been updated for years, and its next version has been in alpha for 6 years.
People may think it is not updated because the API is stable and does not need change. The reality is: Express does not know how to handle async/await
.
Matteo Collina@matteocollinaYet another Nodejs project recommends using async/await in Express middlewares.
I only see memory leaks everywhere. Hopefully from @nodejs v15 we crash on unhandledRejection.. at least theyll all see their problems before reaching production.20:53 PM - 13 Jan 2021
If you are using async/await
code inside your route's handler or middleware, you are prone to UnhandledPromiseRejectionWarning
exception. Express will not handle those exceptions for you because it does not know them.
There are multiple issues (#4360, #4348, ...) in Express' repository about people having this problem.
You should know that from Node 15, your application will crash when encountering this exception, and before this version, you will have a memory leak.
When using async/await
, you should always ensure that the library accepts an AsyncFunction
as a callback. Here is a great talk named Broken Promises about that.
--
It is a low-scope framework
The word "framework" is a wild term. When you are looking closer, Express is a routing library that supports middleware, but it is still called "a framework".
Evan You had a great talk about seeking the balance in a framework design. He said that we should categorize a framework by its scope.
We can categorize Express as a low-scope framework.
When you are building an application, you need more features than a routing system.
You need to:
- access a database;
- validate your data;
- create an authentication layer;
- create an authorization system;
- etc.
All of those features are not inside Express and should be glued by yourself.
I've always been amazed to see people fighting so hard to make something work by glueing modules instead of choosing a real solution to their problem.
Stop creating your undocumented homemade-framework on top of routers and start working on what matter. twitter.com/_bitkidd/statu07:37 AM - 10 Sep 2020Kirill @_bitkiddWrote a short story of my way to @adonisframework and why I chose it for every day workhttps://t.co/e6bCrXhqeK
Gluing those modules yourself means taking all the risk to add memory leaks, security holes, and bugs to your application. On top of that, you are only losing time and money because you should not be the one responsible for doing that.
--
Alternatives
What are the alternatives? What should we teach to people?
Even if I believe low-scope framework should not be used, there are few people that like this style or need one for learning purposes. In this category, you should look at fastify.
This framework is well maintained, and provides an official compatibility layer for Express to help you migrate your application.
If you prefer to have a high-scope fully-featured framework that lets you focus on your business logic, you can use AdonisJS.
There is no reason to stay with Express, only future pain that you can avoid today.
--
Do I hate Express?
The goal of this section is to add a disclaimer to this article. I am not hating Express. I am sharing my perspective to help others make informed decisions and not follow the herd.
Express was one of the first frameworks in the Node.js ecosystem, and it was great for many years! But now, it is time to let it go.
I want to push the Node.js Ecosystem further and help newcomers to learn a technology that will not explode in their hands.
Original Link: https://dev.to/romainlanz/why-you-should-drop-expressjs-in-2021-711
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To