Live data from Hacker News

Fetch API has landed into Node.js

github.com

1–10 of 210 posts

Re: Fetch API has landed into Node.js

#3
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.

https://www.npmjs.com/package/undici

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.

Re: Fetch API has landed into Node.js

#4
Hey, Node core person here (and the person who triggered the land) - we're super excited for this and would love help and feedback.

This is still experimental and we'd love to hear from the community what you'd like to see.

Re: Fetch API has landed into Node.js

#6
post #2

For those of us unfamiliar, how long until stuff comes out of experimental?

In general "when we feel it's ready". For some features I've worked recently (like `flatMap` and friends for streams) I think it'll take about a year.

For `fetch` it will take us around a year or two probably.

I wrote more details on the PR itself but I (and others) basically feel strongly that it should be as close to compliant as possible (Deno have a nice list which they happily shared with us of how they diverge and that seems reasonable).

Basically there is a bunch of stuff that should happen first:

- We need to run (and pass) the web platform tests.

- We want to go over the spec (again) and check compliance and add more tests and fix bugs.

- We want community feedback on the implementation and to improve the DX to be better (while not sacrificing spec compliance).

- We want better support for stuff like `File` in core.

- Web streams need to go out of experimental first.

This was a _long_ road that had many stepping stones (like EventTarget, AbortController, Blob, ReadableStream etc). It's important to get it right.

Worth mentioning the fact it's experimental doesn't mean it's not safe to use in simple code in this case - it just means if you make your code behave in a way that diverges from the specification we may change our implementation to match the specification and break your code.

Anything like `await fetch('./someUrl').then(x => x.text())` should be fine.

Re: Fetch API has landed into Node.js

#7
post #5

Brief explanation?

Fetch is a web JS API to do HTTP requests. NodeJS has its own API to do HTTP requests. This add supports for the fetch API.

I think the only benefit it that it makes it easier to share code between front end and back end.

Re: Fetch API has landed into Node.js

#9
post #7
post #5

Brief explanation?

Fetch is a web JS API to do HTTP requests. NodeJS has its own API to do HTTP requests. This add supports for the fetch API. I think the only benefit it that it makes it easier to share code between front end and back end.

For more on Fetch, check out MDN: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

Re: Fetch API has landed into Node.js

#10
post #4

Hey, Node core person here (and the person who triggered the land) - we're super excited for this and would love help and feedback. This is still experimental and we'd love to hear from the community what you'd like to see.

I do have a question that's only tangibly related to fetch, I was wondering what Nodes stance is on the seemingly increasing gap between the NodeJS and browser implementations of the JavaScript engine.

It's still very common to see Node modules that use require(), for example, but would otherwise work flawlessly in a browser where there is no require() support (without using shims and other libraries).

Post reply on HN