Demonstrate the functionalities of fs module in asynchronous mode.
Mon Apr 07 2025 23:55:17 GMT+0000 (Coordinated Universal Time)
Saved by
@p9876543
const fs = require('fs');
fs.writeFile('async.txt', 'This is written using writeFile (Async)', (err) => {
if (err) throw err;
console.log('File created and written successfully.');
fs.readFile('async.txt', 'utf8', (err, data) => {
if (err) throw err;
console.log('File content:', data);
fs.appendFile('async.txt', '\nThis is an additional line (Async)', (err) => {
if (err) throw err;
console.log('Content appended.');
fs.unlink('async.txt', (err) => {
if (err) throw err;
console.log('File deleted.');
});
});
});
});
content_copyCOPY
Comments