Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js "on" function - What does it do?

 var rd = readline.createInterface({
    input: fs.createReadStream(file),
    output: process.stdout,
    terminal: false
});

rd.on('line', function(line) {

And is any way how to make "on" working synchronous. Code inside "on" loop need to be done before executing loop again. Is any way how to do that?

like image 734
user2316602 Avatar asked Oct 29 '25 16:10

user2316602


1 Answers

Generally, the on function registers an event handler for a specific event.

The readline::line event serves for this purpose:

Emitted whenever the input stream receives a \n, usually received when the user hits enter, or return. This is a good hook to listen for user input.

— NodeJS documentation

By the way, which keywords did you use for your search? I used nodejs readline.createInterface and the first result was this NodeJS documentation page!

like image 107
ComFreek Avatar answered Nov 01 '25 06:11

ComFreek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!