Fireship · @fireship

BIG new feature lands in Node.js // The Code Report

Uploaded February 4, 2022 · Length 2:52

BIG new feature lands in Node.js // The Code Report

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.

  1. 0:01

    it is february 4th 2022 and you're

  2. 0:04

    watching the code report news you can

  3. 0:06

    use javascript developers are famous for

  4. 0:08

    their ability to reinvent the wheel in

  5. 0:10

    node.js for example there are many ways

  6. 0:12

    to work with the hypertax transfer

  7. 0:14

    protocol if you hate yourself you might

  8. 0:16

    use its built-in http module but there

  9. 0:18

    is a smorgasbord of third-party packages

  10. 0:20

    like axios node fetch got request super

  11. 0:23

    agent and hundreds of others they're

  12. 0:25

    extremely popular and account for tens

  13. 0:27

    of millions of weekly downloads just

  14. 0:29

    this week developers got some surprise

  15. 0:30

    news with a pull request adding support

  16. 0:32

    for the fetch api natively in node.js

  17. 0:35

    just a mere six years or so after it

  18. 0:37

    became an industry standard via what

  19. 0:38

    double eug stop trying to make fetch

  20. 0:40

    happen it's not going to happen fetch is

  21. 0:43

    not perfect but it has proven itself to

  22. 0:44

    be good enough to where we don't need to

  23. 0:46

    wrap it with a billion other packages

  24. 0:48

    just to avoid mental health issues but

  25. 0:50

    why is this a big deal well fetch

  26. 0:51

    provides a generic definition of request

  27. 0:53

    and response objects and allows you to

  28. 0:55

    manage them with a simple promise-based

  29. 0:57

    api because fetch and node is pretty

  30. 0:59

    much identical to the browser developers

  31. 1:01

    have less mental overhead when

  32. 1:02

    translating between front-end and

  33. 1:04

    back-end code sharing common apis also

  34. 1:06

    makes it much easier to develop packages

  35. 1:08

    that work both in node and the browser

  36. 1:10

    it's something that other runtimes like

  37. 1:12

    dino and cloudflare workers have already

  38. 1:14

    implemented so they deserve some credit

  39. 1:16

    for giving node some friendly

  40. 1:17

    competition fetch sounds cool so how do

  41. 1:19

    i use it as of today it's not in a

  42. 1:21

    public release but you could build node

  43. 1:22

    from source if you're really motivated

  44. 1:24

    keep your eyes peeled for node version

  45. 1:26

    17.5 where it should be available under

  46. 1:28

    an experimental flag then expect it to

  47. 1:30

    be a standard issue weapon by note 18.

  48. 1:32

    the implementation is based on a package

  49. 1:34

    you can use today called undici which is

  50. 1:36

    named after the character 11 and

  51. 1:37

    stranger things we can install it in a

  52. 1:39

    node project then import fetch it makes

  53. 1:41

    scripting a node really nice because to

  54. 1:43

    make a git request all we have to do is

  55. 1:44

    await fetch to access data from any

  56. 1:47

    website or api and we don't even need an

  57. 1:49

    async function because node also

  58. 1:50

    supports top level await now to make a

  59. 1:52

    post request we can use the same

  60. 1:54

    function and modify some of its options

  61. 1:56

    like the method body and headers that's

  62. 1:58

    pretty nice but one question on a lot of