我正在尝试将config包集成到我的nx.dev类型记录项目中。我有一个根级的config目录,其中包含default.json。
{
"server": { "port": 3001 }
}在我的index.ts里我试着
import { get, util } from 'config';
console.log(util.getConfigSources());
console.log(get('server'));得到以下信息:
[
{
name: 'path to config file.. /config/default.ts',
original: '{\n "server": {\n "port": 3001\n }\n}',
parsed: { server: [Object] }
}
]
Error: Configuration property "server" is not defined在任何地方,它都说这是我需要连接的全部,但是get函数抛出。
发布于 2022-09-19 17:53:24
node-config get方法被设计为--并记录在案--作为config对象的方法调用。尝试使用文档化的导入语法:
const config = require('config');
console.log(config.get('server'));在JavaScript中作为函数调用时,不能期望对象方法同样工作。对象方法将this绑定到该对象。除非在函数上显式调用bind()将其绑定到对象,否则函数不会。
https://stackoverflow.com/questions/70983800
复制相似问题