Did you try isomorphic-fetch?
Re:ECMAScript 2016 Approved
by BinaryIdiot on Friday June 17, 2016 @09:03AM
(#11922364)
No; node and the browser provide APIs that do this already they're just very different so I simply wrapped them to avoid dependencies (it was pretty easy). But I knew of it and it's a good idea.
jQuery is mostly a better library for dealing with the DOM though. It has support for making network calls but those don't work in node without polyfills.
> Though I guess this is what standards are for. I would like to see a browser try this anyways, though. That would be the fastest way to get the standards bodies to acknowledge the problem.
I mean fetch exists and is an HTML 5 standard that's fairly decoupled from the DOM, unlike XMLHttpRequest. But it has to also work in node.js. I wrote a set of HTTP methods in my msngr library that works in both node.js and the web browser but it feels like a hack. I want my language to have first class networking and file io.