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 --…
Fetch API has landed into Node.js
91–100 of 210 posts
Re: Fetch API has landed into Node.js
#92Earlier 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.
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
#93Hey, 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
#94As someone browser focused this surprised me. I've been using fetch() for years now.
Re: Fetch API has landed into Node.js
#95Earlier 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!
Re: Fetch API has landed into Node.js
#96I 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?
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.
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
#97I 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?
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
#98Hey, 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
#99Earlier 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…
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
#100Earlier 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.
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.