Reading the official docs for the readline module, there is no end
event like other streams. Trying
reader.on('end', cb);
Doesn't work.
How can I run a callback once there are no more lines to be read?
createInterface( process. stdin, process. stdout); The method createInterface() takes two parameters – the input stream and output stream – to create a readline interface.
Here's the easiest way to read lines from a file, without any external modules: const fs = require('fs'); const readline = require('readline'); async function processLineByLine() { const fileStream = fs. createReadStream('input. txt'); const rl = readline.
The Readline module provides a way of reading a datastream, one line at a time.
To use the module, you need to import it to your JavaScript file as follows: const readline = require('readline'); Next, you need to write the code for receiving user input or reading file content, depending on your requirement.
Nevermind, it's close
.
reader.on('close', cb);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With