Created
October 13, 2024 08:48
-
-
Save pshaddel/05248c7ae9d644182ae1fe4fd522a798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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