我试图将一个字符串附加到日志文件.但是,writeFile会在每次写入字符串之前删除内容.
fs.writeFile('log.txt', 'Hello Node', function (err) {
if (err) throw err;
console.log('It\'s saved!');
}); // => message.txt erased, contains only 'Hello Node'
Run Code Online (Sandbox Code Playgroud)
知道怎么做这个简单的方法吗?
丹尼尔
我有另一个问题(最后一个问题).目前我正在开发一个Node.js项目,在这个项目中我有很多 console.log()函数.到目前为止,这一切都运行正常,但我也希望写入控制台的所有内容也都写在日志文件中.有人可以帮帮我吗?
例如:
Console.log('The value of array position [5] is '+ array[5]);
Run Code Online (Sandbox Code Playgroud)
在我的真实代码中它更多但这应该给你一个想法.
谢谢你.