Skip to content

Instantly share code, notes, and snippets.

@pshaddel
Created October 13, 2024 08:48
Show Gist options
  • Save pshaddel/05248c7ae9d644182ae1fe4fd522a798 to your computer and use it in GitHub Desktop.
Save pshaddel/05248c7ae9d644182ae1fe4fd522a798 to your computer and use it in GitHub Desktop.
const fs = require('fs');
function read_file_1(repeat, count = 0) {
if (count >= repeat) return;
fs.readFile('./hello.txt', 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
console.log(data);
read_file_1(repeat, count + 1); // Call the function recursively
});
}
// Get the number of times we should repeat the read operation
const repeat = parseInt(process.argv[2], 10) || 1;
read_file_1(repeat);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment