Node.js Write a line into a .txt file

前端 未结 4 1605
难免孤独
难免孤独 2020-12-04 17:24

I want to create a simple Log System, which prints a line before the past line into a txt file by using Node.js, but i dont know how the File System from Node.js works. Can

4条回答
  •  Happy的楠姐
    2020-12-04 18:23

    Simply use fs module and something like this:

    fs.appendFile('server.log', 'string to append', function (err) {
       if (err) return console.log(err);
       console.log('Appended!');
    });
    

提交回复
热议问题