Live data from Hacker News

Fetch API has landed into Node.js

github.com

11–20 of 210 posts

Re: Fetch API has landed into Node.js

#11
post #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).

I don't speak for the project a whole :)

Node has supported ESModules (`import`) for a while and you can use it (either by naming your files `.mjs` or setting `type: module` in your package.json.

There is a solid interop story between require/import and you can mix if you want.

`require` is going to be supported "forever" so code doesn't break and both module systems work.

As for the general question: Node is committed to supporting modern JavaScript and to not allow such a gap to be created. If you see a place Node doesn't do a great job at that please tell us!

Re: Fetch API has landed into Node.js

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

It makes it easier to learn and develop both frontend and backend.

Re: Fetch API has landed into Node.js

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

Hey this one change is going to positively impact my day to day life. Just wanted to let you know. Thanks for sharing your hard work and time.

Re: Fetch API has landed into Node.js

#16
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?

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?

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?

Does anyone who knows enough JavaScript point me in the right direction about it. I find all this very confusing.

Re: Fetch API has landed into Node.js

#17
post #16

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? 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? Also why do so many libraries have this strange 5 line…

Node supports ES Modules (the import statements you mention) natively now: https://nodejs.org/api/esm.html

Re: Fetch API has landed into Node.js

#18
post #16

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? 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? Also why do so many libraries have this strange 5 line…

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 bother updating.

I still use amd in my job at Microsoft though for some things so I guess it's not useless :)

Re: Fetch API has landed into Node.js

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

This is an understatement. With fetch available in node, we have a single, standardised, promise-based HTTP client Interface available on all (more or less common) JavaScript platforms.

This is great news for an ecosystem traditionally extremely fragmented and may lead the way to more consolidation in the JS library space.

Re: Fetch API has landed into Node.js

#20
post #16

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? 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? Also why do so many libraries have this strange 5 line…

[deleted]
Post reply on HN