我尝试编写一些完成现有文件的nodejs代码。但每次我启动脚本时,它都会写入我的测试文件的内容。
var fs = require('fs');
var writer = fs.createWriteStream('test.txt', {flags: 'w'});
writer.on('finish', function() {
console.log('data has been saved successfully');
});
function writeInList(id) {
console.log(id);
writer.write(id+' \n');
}
for (var id = 0; id<10; id++){
writeInList(id);
}
writer.end();
当然,我已经找到了解决方案:
Writing large files with Node.js
但是我无法让它运行。请问有人帮帮我吗?