NodeJS app.js requiring a JSON file?

I know that if I had some JSON data in a .js file, that I could, at the end of that .js file, do a module.exports() of that JSON module's name, and then require it in my app.js, and use a res.json() on it. (pics 1-3)

But what if instead of having that JSON data in a js file, it was housed in its own .json file?

I couldn't do a module.exports() from inside a .json file.

Simply requiring the file inside of app.js and using the same res.json() on it doesn't work.

Are we meant with NodeJS to just convert any JSON files to .js first if we intend to use it in app.js, in order to get access to it?
Screen_Shot_2023-05-24_at_5.55.36_PM.png
Screen_Shot_2023-05-24_at_5.56.24_PM.png
Screen_Shot_2023-05-24_at_6.02.08_PM.png
Screen_Shot_2023-05-24_at_6.06.12_PM.png
Screen_Shot_2023-05-24_at_6.06.40_PM.png
Was this page helpful?