0
I have on abc.js file in node side.Having below content:
abc.js갱신
"use strict";
// Test specific configuration
// ===========================
module.exports = {
port: process.env.PORT || 8101,
api:{xyz:"old"}
}
while using below code to update api->xyz value :
nodetest.js
덮어 abc.js에서var fs = require('fs');
var fileName = './abc.js';
var file = require(fileName);
file.api.xyz= "new";
fs.writeFile(fileName, JSON.stringify(file, null, 2), function (err) {
if (err) return console.log(err);
console.log(JSON.stringify(file));
console.log('writing to ' + fileName);
});
I am getting below output in abc.js
{
"port": 8101,
"api":{"xyz":"new"}
}
, "엄격한 사용", "module.exports" 코멘트가 없습니다. 어떻게 abc.js 파일의 모든 내용을 동일한 형식으로 "xyz"값의 변경된 값으로 유지할 수 있습니까?
원하는 출력은 다음과 같아야합니다
abc.js 난 당신이 수동으로 require
에게 그들을, 유일한 것은 당신이로 가져 오는 경우 이후에 다시 추가해야합니다 생각
"use strict";
// Test specific configuration
// ===========================
module.exports = {
port: process.env.PORT || 8101,
api:{xyz:"new"}
}