How to append to New Line in Node.js

后端 未结 3 1050
执念已碎
执念已碎 2020-12-02 09:57

I\'m trying to Append data to a Log file using Node.js and that is working fine but it is not going to the next line. \\n doesn\'t seem to be working in my fun

3条回答
  •  攒了一身酷
    2020-12-02 10:10

    Use the os.EOL constant instead.

    var os = require("os");
    
    function processInput ( text ) 
    {     
      fs.open('H://log.txt', 'a', 666, function( e, id ) {
       fs.write( id, text + os.EOL, null, 'utf8', function(){
        fs.close(id, function(){
         console.log('file is updated');
        });
       });
      });
     }
    

提交回复
热议问题