Since this is a .json
file, Benjamin's answer works just fine (just require()
it in).
If you have any configs that are valid JSON but not stored in files that end in a .json
extension, you can use the jsonfile module to load them in, or use the slightly more verbose
JSON.parse(require('fs').readFileSync("...your file path here..."))
(if you have fs
already loaded, this tends to be the path of least resistance)
The one big difference between require
(which pretty much uses this code to load in json files) and this code is that require
uses Node's caching mechanism, so multiple require
s will only ever import the file once, and then return points to the parsed data, effectively making everything share the same data object. Sometimes that's great, sometimes it's absolutely disastrous, so keep that in mind
(If you absolutely need unique data, but you like the convenience of require
, you can always do a quick var data = require("..."); copied = JSON.parse(JSON.stringify(data));
)