0
votes

I have an npm module that requires a config file (provided by the user). Is there a way to tell that module to look for a specific file in the user's directory ?

I want something like this:

In the module

const config = require(USER_ROOT_DIRECTORY + '/config.json');

In the user's project

/node_modules (contains the module file)

/src/index.js

/config.json

In the index.js file

const module = require('module'); // will automatically get the config.json file's content

1

1 Answers

0
votes

You can use absolute path since you know with npm module requires what file simply add the path inside the module file better to add in index.js example-

var config = require('./subfolder/config.json')