How to append to a file in Node?

后端 未结 18 1479
庸人自扰
庸人自扰 2020-11-22 09:23

I am trying to append a string to a log file. However writeFile will erase the content each time before writing the string.

fs.writeFile(\'log.txt\'         


        
18条回答
  •  执笔经年
    2020-11-22 10:11

    Node.js 0.8 has fs.appendFile:

    fs.appendFile('message.txt', 'data to append', (err) => {
      if (err) throw err;
      console.log('The "data to append" was appended to file!');
    });
    

    Documentation

提交回复
热议问题