thadeuszlay thadeuszlay - 1 year ago 126
JSON Question

How to add json file in file in the utils folder of nodeJS?

I've got a JS file in the utils folder of a nodeJS project. That JS file is responsible for loading data from a database. Right now I only have dummy data that is put in a local JSON file. Now I want to load this local JSON file in my JS file. How do I do this?

I can't use HTTP requests because it's a local JSON file. I can't use use jQuery's

because you can't integrate jQuery into that file.

Is the only thing I can do is inserting the whole JSON object into my JS file?

Answer Source

The require() function can parse and return JSON files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download