Fireship · @fireship
BIG new feature lands in Node.js // The Code Report
Uploaded February 4, 2022 · Length 2:52
Summary
Node.js gets native support for fetch API, replacing need for third-party packages like Axios.
- nodejs
- fetch api
- axios alternative
- javascript
- web development
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:01
it is february 4th 2022 and you're
- 0:04
watching the code report news you can
- 0:06
use javascript developers are famous for
- 0:08
their ability to reinvent the wheel in
- 0:10
node.js for example there are many ways
- 0:12
to work with the hypertax transfer
- 0:14
protocol if you hate yourself you might
- 0:16
use its built-in http module but there
- 0:18
is a smorgasbord of third-party packages
- 0:20
like axios node fetch got request super
- 0:23
agent and hundreds of others they're
- 0:25
extremely popular and account for tens
- 0:27
of millions of weekly downloads just
- 0:29
this week developers got some surprise
- 0:30
news with a pull request adding support
- 0:32
for the fetch api natively in node.js
- 0:35
just a mere six years or so after it
- 0:37
became an industry standard via what
- 0:38
double eug stop trying to make fetch
- 0:40
happen it's not going to happen fetch is
- 0:43
not perfect but it has proven itself to
- 0:44
be good enough to where we don't need to
- 0:46
wrap it with a billion other packages
- 0:48
just to avoid mental health issues but
- 0:50
why is this a big deal well fetch
- 0:51
provides a generic definition of request
- 0:53
and response objects and allows you to
- 0:55
manage them with a simple promise-based
- 0:57
api because fetch and node is pretty
- 0:59
much identical to the browser developers
- 1:01
have less mental overhead when
- 1:02
translating between front-end and
- 1:04
back-end code sharing common apis also
- 1:06
makes it much easier to develop packages
- 1:08
that work both in node and the browser
- 1:10
it's something that other runtimes like
- 1:12
dino and cloudflare workers have already
- 1:14
implemented so they deserve some credit
- 1:16
for giving node some friendly
- 1:17
competition fetch sounds cool so how do
- 1:19
i use it as of today it's not in a
- 1:21
public release but you could build node
- 1:22
from source if you're really motivated
- 1:24
keep your eyes peeled for node version
- 1:26
17.5 where it should be available under
- 1:28
an experimental flag then expect it to
- 1:30
be a standard issue weapon by note 18.
- 1:32
the implementation is based on a package
- 1:34
you can use today called undici which is
- 1:36
named after the character 11 and
- 1:37
stranger things we can install it in a
- 1:39
node project then import fetch it makes
- 1:41
scripting a node really nice because to
- 1:43
make a git request all we have to do is
- 1:44
await fetch to access data from any
- 1:47
website or api and we don't even need an
- 1:49
async function because node also
- 1:50
supports top level await now to make a
- 1:52
post request we can use the same
- 1:54
function and modify some of its options
- 1:56
like the method body and headers that's
- 1:58
pretty nice but one question on a lot of


