panzerdp / dmitripavlutin.com-comments

7 stars 0 forks source link

javascript-json-modules/ #152

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

JSON Modules in JavaScript

How to import JSON data directly into an ES module.

https://dmitripavlutin.com/javascript-json-modules/

SiR-PENt commented 2 years ago

Thank you for this! I was wondering earlier this week if I had to always do this with fetch

panzerdp commented 2 years ago

Thank you for this! I was wondering earlier this week if I had to always do this with fetch

You're welcome @sukodes! Yes, including JSON natively is a must.

strat-x commented 2 years ago

Thx for the article! For those trying this out I think it might be useful to highlight that import is only available in modules. In order to let nodejs treat your js file as a module you must add "type": "module", to your package.json.

panzerdp commented 2 years ago

Thx for the article! For those trying this out I think it might be useful to highlight that import is only available in modules. In order to let nodejs treat your js file as a module you must add "type": "module", to your package.json.

You can also take a look at my post How to Use ECMAScript Modules in Node.js.

AliN11 commented 2 years ago

Thanks for sharing Dmitri!

xerosource01 commented 1 year ago

Really helpful !! Thanks for the article

panzerdp commented 1 year ago

@xerosource01 You're welcome!