Kiran Chauhan

Cogito, ergo sum // I think, therefore I am.

TIL: fetch() in Node is powered by undici

Undici means eleven in Italian. It is an HTTP/1.1 client. 1.1 -> 11 -> Eleven -> Undici.

fetch() that we use in Node is actually from undici library/package. As this library is written and maintain by Node team and part of Node runtime, we directly get fetch() function without installing it separately as external package.

But, if you want, you can still use it as project dependency using following command:

npm i undici

If following is the code we have:

const resp = await fetch("http://api.example.com/data");

Then we need to add fetch import statement as:

import { fetch } from "undici";

const resp = await fetch("http://api.example.com/data");

Yes, drop-in replacement!

Most of the time, we don't need this library unless we want to use latest and greatest feature of library that are yet not available within Node. But, doing so will add burden to manage the additional dependency. Plus, it will increase the bundle size as it is now a package used by our app than the runtime itself.