The node.js team has an alternative HTTP client, it can run HTTP requests about 2-3 times faster than the built-in HTTP module. With node.js version 15, the advantage is up to 4 times. This is important because almost every other HTTP client such as
axios use the original build-in HTTP client of node.js under the hood. And after the
request lib is marked deprecated, here might be a good alternative.
The new HTTP client is called undici and can be found on npm and on GitHub under the node.js organization.
- It requires to create a
clientobject for every destination server you want to access. Still, the API is clean and you will be quickly able to adopt it. In the constructor, you have some options for concurrency.
- The client uses the build-in
netmodule instead of the
- As the HTTP lib, it uses
keepAliveto use multiple queries over the same TCP connection, but it does not wait for responses to send out more requests. In the documentation they name it pipelining.
Do you think
fastify also became faster than the native http module by using the
net module? I have to read that code.
Earlier this year I build an experimental web server using the
net module. you can read my article.
What are your thoughts on
undici? Please leave a nice comment.