我有一个如下所示的配置文件。我正在尝试删除 customLog2
值:
{
"customLog2": {
"key": "2",
"value": "example"
},
"customLog3": {
"key": "3",
"value": "result"
}
}
nconf.file(configFile);
nconf.remove('customLog2');
nconf.save(function (err) {
fs.readFile(configFile, function (err, data) {
if (err) console.log(err);
console.dir(JSON.parse(data.toString()))
});
});
我仍然在文件中看到 customLog2。
最佳答案
根据nconf README documentation ,remove 函数用于从 nconf 对象中删除整个“数据存储”,而不是单个键。
它与 add/use 相反方法。
关于node.js - nconf 不会从配置文件中删除这些值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23453901/