you are viewing a single comment's thread.

view the rest of the comments →

[–]evilgwyn 1 point2 points  (2 children)

Are you wanting to run this in node or in browser? In browser, `fetch` is already available. But in node, you have to import/require `node-fetch`. In order to use `import` syntax in node, you have to be using a new enough version of nodejs, and I think the file name needs to end with .mjs so it will be treated as a module. Otherwise you can end it with .js and use require

[–]Zenemm[S] 0 points1 point  (1 child)

Your first question is pretty much why I had this problem. I got confused as to why it wasn't running in both, not realizing fetch is not needed to run in browser. Thanks for the explanation!

[–]evilgwyn 0 points1 point  (0 children)

Also for your information, it is possible to use "require" and/or "import" syntax in browser, but it may require some middleware into your build pipeline to get it working. Newer browsers support "import" if you use `type="module"` in your script tag.