Hey, Node core person here (and the person who triggered the land) - we're super excited for this and would love help and feedback.<p>This is still experimental and we'd love to hear from the community what you'd like to see.
Every Node.js dev should be thanking the Deno creators. It has forced them off of their "this is how Node does it" complacency. Most improvements I notice and care about on Node these days are all things that Deno already supports (fetch, ES modules, async std lib uses promises, etc).<p>The Web Platform APIs aren't perfect, but they are better, and more thoroughly thought out than Node's.
My biggest issue with node when I was working on it briefly was I couldn't do the 'import' statements like wepback. Are they supported too now?<p>I'm not a web developer so I had a very hard time understanding why there are so many different type of imports in JavaScript like require, import, umd, amd, etc and which one works in browser and which one works in node?<p>Also why do so many libraries have this strange 5 line header code for this umd, amd, business. Is that to make their packages work with nodejs?<p>Does anyone who knows enough JavaScript point me in the right direction about it. I find all this very confusing.
One thing I hate about fetch() is that you can't manually follow redirects. Using { redirect: 'manual' } doesn't expose the Location header of the redirect, so it's essentially useless. I know that node-fetch fixed this issue, so I hope the official Node fetch() does not have the same problem.
I love fetch, except for the way that it combines headers. If more than one of the same header is set (such as multiple set-cookie headers), it combines them all into a single comma-separated string. I know this is allowed in the HTTP spec, and it's probably even a sensible default. But the fetch spec doesn't allow any access to the raw headers, so there's no straightforward way to get the original uncombined headers back. Set-Cookie headers, in particular, often contain commas in their expiration dates, so just splitting around `, ` will lead to problems.<p>I took a look through the source of this new fetch API, and it seems to have inherited that wart:
<a href="https://github.com/nodejs/undici/blob/2dd3437e20c5a3cc466226c544f048351baffc78/lib/fetch/headers.js#L103" rel="nofollow">https://github.com/nodejs/undici/blob/2dd3437e20c5a3cc466226...</a><p>I've argued with the authors of the fetch spec about this before, and ultimately settled on using <a href="https://www.npmjs.com/package/set-cookie-parser#user-content-splitcookiesstringcombinedsetcookieheader" rel="nofollow">https://www.npmjs.com/package/set-cookie-parser#user-content...</a> to work around this flaw. (For clarity, I published the package, but chrusart wrote that method - <a href="https://github.com/nfriedly/set-cookie-parser/pull/19" rel="nofollow">https://github.com/nfriedly/set-cookie-parser/pull/19</a>)
There’s an NPM package containing this implementation called ‘undici’ that you can install in previous versions of Node; the package.json claims support back to 12.x.<p><a href="https://www.npmjs.com/package/undici" rel="nofollow">https://www.npmjs.com/package/undici</a><p>However the fetch implementation itself is documented as unstable and only supports Node 16.x. I believe this is because it is not quite spec compliant yet, so there is latitude for breaking changes that make it more spec compliant.
Does this contain `request.formData()` and `FormData`?<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Request/formData" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/API/Request/for...</a>
<a href="https://developer.mozilla.org/en-US/docs/Web/API/FormData" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/API/FormData</a>
Good for NodeJS<p>However, I feel the fetch API is completely botched because it lacks timeout support. I have cobbled some together for <a href="https://github.com/Backblaze/gists/pull/8" rel="nofollow">https://github.com/Backblaze/gists/pull/8</a> but gosh. I really hope all that is actually not necessary :/
sorry if this is a stupid question, but how do I try this out? I ran node with the experimental flag on a file that calls fetch:<p>node server.js --experimental-fetch<p>Got 'fetch is not defined' reference error.
Ive used Fetch in the past, great lib. I'm curious why Node core has decided to make this an official part of Node? From one perspective there could be a hard argument that this should never be a part of Node as it is an external library and not a building block of the language? Almost feels like feature creep for the core language? I know that's not the intent, but wanting to understand the logic behind this decision :)
Good that some people are happy about this, but it really is pointless to post a link to "lib: add fetch" followed by code diffs. HN should have a requirement that there be an actual post, rather than a discussion starter for those in a particular community. All you'd have to do is type in a brief text post with an explanation and then link to the code diffs for those interested.
Funny how my brain works, I thought it was there already, but I must have got so used to having it as a dependency I forgot that it was a dependency not built in. To be fair I don't "Node" all the time! It's on and off.
Can you set more than one cookie in the request and read more than one cookie in the response? Was shocked when I learnt that's not supported by the spec..
I love that the most popular language's core lib now brings a trivial bit of code available in every other platform and its a celebrated super achievement<p>software, why do you suck now?