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:
const config = require(USER_ROOT_DIRECTORY + '/config.json');
/node_modules (contains the module file)
/src/index.js
/config.json
const module = require('module'); // will automatically get the config.json file's content
答案 0 :(得分:0)
你可以使用绝对路径,因为你知道npm模块需要什么文件只需添加模块文件里面的路径更好地添加到index.js例子中 -
var config = require('./subfolder/config.json')