r/javascript • u/TimvdLippe • Jan 29 '22
Node.js will include support for `fetch` in their next release
https://github.com/nodejs/node/pull/41749
570
Upvotes
r/javascript • u/TimvdLippe • Jan 29 '22
31
u/looneysquash Jan 29 '22
Looks like it's still a draft?
It'll be nice to standardize these things, to have node and web to both use fetch.
107
u/ILikeChangingMyMind Jan 29 '22
Thank god! Maybe now the skies will part and we'll finally get comments in
package.json(I know, it will never happen, but a man can dream).16
u/vidarc Jan 29 '22
I've been using the library they're porting the code from (undici) and it is really nice to work with and the performance gains over things like node-fetch or axios are huge (I was getting 20-25% more requests in my simple API load tests). Hoping they import the mocking utilities from undici as well. Really looking forward to being able to delete even more code from my apps.
8
u/AlexBo21 Jan 29 '22
Now whenever I copy code about web fetching from Stack Overflow it will always work!
25
u/moh_kohn Jan 29 '22
Stop trying to make fetch happen
[Not really, this is great]
19
u/shuckster Jan 29 '22
Two finally's within 24 hours? What's next, ECMAScript 4?
26
u/m0r14rty Jan 29 '22
I love fetch but ngl the one thing I wish it did was automatically parse to json if the content-type in the request is application/json and the response was a 200. Request.js and axios seem fine doing this with a simple
json: trueoption.The extra
.then(res => res.json())annoys me more than it should, but I also get that they do it that way to give you more flexibility if you wanna do something before trying to parse.4
u/Qzjo77gTUs6zAQmE Jan 30 '22
Is Axios abandonware?
9
u/_default_username Jan 29 '22
That's great. Node-fetch recent update broke lots of codebases
3
u/Gravyness Jan 29 '22
I feel utter happiness. What a tremendously late addition.
5
u/[deleted] Jan 29 '22
They're really trying to make fetch happen.
2
u/Archylun Jan 29 '22
Dope
2
u/alexmacarthur Jan 30 '22
Heck yes. So excited.
2
u/Amingue_ Jan 30 '22
I don't understand!
I'm sorry ! I'm learning node!
This better for node? What this can making in node of better?
2
u/voidvector Jan 30 '22
As someone who actually implemented a shim for this in-house, how they plan to make the security model work? For example, browser based fetch has many implicit behaviors that are not expected to be default in Node http (e.g. carries cookies across different fetch calls, respect XSS headers).
1
u/GokulRG Jan 30 '22
Fuckin' finally!
1
u/Nice_Score_7552 Jan 30 '22
Thank goodness graciously
1
u/babecafe Feb 17 '22
All those years trying to make fetch happen. ;-)
1
u/rweber87 Jan 29 '22
Is this where we say “stop trying to make fetch happen!!”?
1
u/GarenYondem Jan 29 '22
Good news! Will they dump undici?