loading...
Cover image for The fastest HTTP client for node.js by node.js

The fastest HTTP client for node.js by node.js

bias profile image Tobias Nickel Originally published at tnickel.de Updated on ・1 min read

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 node-fetch, request, or 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.

What is the difference?

  1. It requires to create a client object 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.
  2. The client uses the build-in net module instead of the http module.
  3. As the HTTP lib, it uses keepAlive to 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.

Afterthoughts

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.

Discussion

pic
Editor guide