How to append text to text file in Node.js

1 Answer

0 votes
const fs = require('fs');
const path = require('path');
 
const filename = '/test.js';
const text_to_append_to_file = '\nLast line of text';
 
fs.appendFile(path.join(__dirname, filename), text_to_append_to_file, err => {
    if (err) throw err;
    console.log(`Append to file ${filename} success`);
});
 
 
      
/*
run:
    
Append to file /test.js success
  
*/

 



answered Mar 9, 2020 by avibootz

Related questions

1 answer 203 views
1 answer 183 views
183 views asked Mar 9, 2020 by avibootz
1 answer 170 views
1 answer 241 views
1 answer 175 views
1 answer 163 views
...