Reading and Writing File Data in NodeJS

const fs = require('fs');
const line = "Writing this text to a file";
//fs.appendText
fs.writeFile('myfile.txt', line, err => {
    if (err) throw err;
    console.log('text to a file.');
});

fs.readFile('myfile.txt', 'utf8', (err, text) => {
    if (err) throw err;
    console.log(text);
});

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *