Live data from Hacker News

Fetch API has landed into Node.js

github.com

91–100 of 210 posts

Re: Fetch API has landed into Node.js

#91
post #36
post #30

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: node server.js --experimental-fetch Got 'fetch is not defined' reference error.

First: not a stupid question - the release cadence, multiple release lines and other minutia of a project like Node are not something I'd expect users to be intimately familiar with! This _just landed today_. You can get it by building from master: ``` # there is more details in building.md git clone https://github.com/nodejs/node cd node # may need to pass --openssl-no-asm ./configure make -j12 ./out/Release/node --…

Just slightly related to this - I wish I could ask GitHub to send me an email when specific release are available for the repo!

Re: Fetch API has landed into Node.js

#92
post #18

Earlier quoted context omitted.

Those have been supported for several years now :) You need to tell Node to use the format by either naming your file `.mjs` or setting `"type": "module"` in your `package.json` file. > 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? That's just old for "adapt the module system" from the old days and libraries just didn't…

> either naming your file `.mjs` But why? This makes it much harder to ensure that identical code works in browser and nodejs, to the point where I sometimes just can't use nodejs. And I don't use package.json, so having to name files ".mjs" is a really painfull restriction.

If you're hosting the browser-based version over a server like Apache2 (to host the files), you could add a `RewriteRule` to redirect queries to `.js` resources to their `.mjs` counter-part files.

Example: RewriteRule "(.*).js$" "$1.mjs" [R=301 NC]

Reference documentation: https://httpd.apache.org/docs/2.4/rewrite/intro.html

Re: Fetch API has landed into Node.js

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

Do you have any sense of the expected performance of web streams as compared to the existing node.js streams?

Re: Fetch API has landed into Node.js

#94

As someone browser focused this surprised me. I've been using fetch() for years now.

Intercommunicating backend services isn't new, but having an HTTP API call another one from the backend is a case that used to be more normally accomplished by calling both APIs from the frontend. The slow ooze of browser-oriented thinking onto the backend took time. Existing backend engineers, who thought it a harebrained scheme, had to eventually wear down, and give up.

Re: Fetch API has landed into Node.js

#95
post #91
post #36

Earlier quoted context omitted.

First: not a stupid question - the release cadence, multiple release lines and other minutia of a project like Node are not something I'd expect users to be intimately familiar with! This _just landed today_. You can get it by building from master: ``` # there is more details in building.md git clone https://github.com/nodejs/node cd node # may need to pass --openssl-no-asm ./configure make -j12 ./out/Release/node --…

Just slightly related to this - I wish I could ask GitHub to send me an email when specific release are available for the repo!

Sounds like maybe an "if this, then that" kind of thing https://ifttt.com/

Re: Fetch API has landed into Node.js

#96

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 software, why do you suck now?

I don't think you understand this.

e.g., here's your "trivial" API's spec. Then there are the intentional deviations for CORS, e.g., which there is no spec for.

https://fetch.spec.whatwg.org

Not to mention the Fetch API isn't available on every other platform... maybe you're thinking of the general ability to make HTTP requests, but nodejs had that from the start.

Re: Fetch API has landed into Node.js

#97

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 software, why do you suck now?

It’s not trivial and it’s not groundbreaking. Node has had an HTTP client since its inception, this is just a different API. It’s “great” just because it’s a decent abstraction that’s also available in browsers.

The issue in the JavaScript ecosystem for this kind of stuff is that it runs on two very different environments and they need time to find solutions that work for all the parties involved.

Re: Fetch API has landed into Node.js

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

Thanks a ton for this. Fetch API is elegant and it working on node natively will so many edge cases we need to handle currently. Thanks a ton, please know that this will positively change our life and tens of thousands of other developers worldwide.

Re: Fetch API has landed into Node.js

#99
post #33

Earlier quoted context omitted.

Quick question, judging from the commit alone this seems like a rather small change. I assume there's more to it though. I just wonder how come features like this that kind of seems obvious to include in the ecosystem takes quite some time to land? I understand the reality is more complex perhaps, so I am genuinely curious. I hope you realize no disrespect, this will greatly improve the daily work for me since I use…

The commit adds undici (another Node.js project at https://github.com/nodejs/undici ) as a dependency and exposes its `fetch` - the code changes you see are probably just adding a flag :) > I just wonder how come features like this that kind of seems obvious to include in the ecosystem takes quite some time to land? I answered that below (check it out) but note how expensive adding a bad API is vs. asking people for…

To add, unidici is an http client. Node already has http / https, but unidici is much faster and probably has other improvements, too.

They could have built a fetch interface on top of http, but they probably saw an opportunity to make more drastic improvements.

Re: Fetch API has landed into Node.js

#100
post #58

Earlier quoted context omitted.

A new standard would need buy-in from browsers to actually be a standard. Browsers likely don't have a lot of incentive to make spec changes only Node is interested in (like making the whole spec more complicated from their point of view because of Node's (or Deno's) different security model). The level of collaboration and good-faith we've been getting from spec bodies like WHATWG is very high as it is and we really…

Does it have to be a buy-in, though? You could agree on server-specific extensions to fetch and codify them in the same spec (so it doesn't get lost otherwise). Browser vendors wouldn't need to implement it but they will still keep an eye on it when working on future browser apis.

Codifying the redirect behaviour for server/"trusted" envs makes some sense with Deno/node doing the same thing. I'm not versed enough in the standards orginazation politics to say if that's viable though.

The rest of your "improvements" aren't that. They're opinions, opinions laser focused on a JSON centric api.

I'm sorry to say this, but not all of the web is one big JSON blob.

Some of us have to talk to SOAP (xml) services.

Sometimes it's weird rpc stuff with protobuf.

Or even just pulling down raw binary data and feeding that through an API/library that wasn't built for web streams.

Honestly, the amount of code you need to add over the top of a primitive like the Fetch API to get what you wanted (bar the redirect change) is trivial and minimal.

Post reply on HN