0

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 $.getJSON() 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?

thadeuszlay
  • 2,411
  • 6
  • 28
  • 65

1 Answers1

1

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

SLaks
  • 837,282
  • 173
  • 1,862
  • 1,933