adapt-dev adapt-dev - 8 months ago 20
Node.js Question

Can a .json file be read from a dependent library with require()?

I would like to get at a

file in one of my dependent libraries.

using fs to read
doesn't seem foolproof because
could have been installed globally.

Can this be done with


Yes, this can be done with require.

Require, fetches the file and assigns the exports to the assigned variable. In this case,

var jsonObject = require('./node_modules/somelib/properties.json');

should assign the JSON object to jsonObject variable.