【发布时间】:2017-09-04 21:57:33
【问题描述】:
我有一个需要配置文件(由用户提供)的 npm 模块。 有没有办法告诉该模块在用户目录中查找特定文件?
我想要这样的东西:
在模块中
const config = require(USER_ROOT_DIRECTORY + '/config.json');
在用户的项目中
/node_modules(包含模块文件)
/src/index.js
/config.json
在 index.js 文件中
const module = require('module'); // will automatically get the config.json file's content
【问题讨论】:
标签: node.js npm module config require