Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node 'readline' module does not have an 'end' event - how can I do something when there are no more lines?

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?

like image 346
mikemaccana Avatar asked Apr 07 '14 14:04

mikemaccana


People also ask

What is createInterface in node JS?

createInterface( process. stdin, process. stdout); The method createInterface() takes two parameters – the input stream and output stream – to create a readline interface.

How do I read a file line by line in node?

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.

What does readline () do in JavaScript?

The Readline module provides a way of reading a datastream, one line at a time.

How use readline module in node JS?

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.


1 Answers

Nevermind, it's close.

reader.on('close', cb); 
like image 148
mikemaccana Avatar answered Sep 21 '22 08:09

mikemaccana