Writing files in Node.js

前端 未结 19 2077
情歌与酒
情歌与酒 2020-11-21 11:57

I\'ve been trying to find a way to write to a file when using Node.js, but with no success. How can I do that?

19条回答
  •  自闭症患者
    2020-11-21 12:13

    I know the question asked about "write" but in a more general sense "append" might be useful in some cases as it is easy to use in a loop to add text to a file (whether the file exists or not). Use a "\n" if you want to add lines eg:

    var fs = require('fs');
    for (var i=0; i<10; i++){
        fs.appendFileSync("junk.csv", "Line:"+i+"\n");
    }
    

提交回复
热议问题