Browse Source

doc: adds usage of readline line-by-line parsing

In order to make developers aware of node-core built-in
functionality, which might replace module APIs, we should
add an example of readline`s interface usage.
SEO will eventually aid this goal, since it is well searched
on Q&A sites.

PR-URL: https://github.com/nodejs/node/pull/4609
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>>
process-exit-stdio-flushing
Robert Jefe Lindstaedt 9 years ago
committed by Roman Reiss
parent
commit
5a53cba784
  1. 16
      doc/api/readline.markdown

16
doc/api/readline.markdown

@ -232,6 +232,22 @@ line interface:
process.exit(0);
});
## Example: Read File Stream Line-by-Line
A common case for `readline`'s `input` option is to pass a filesystem readable
stream to it. This is how one could craft line-by-line parsing of a file:
const readline = require('readline');
const fs = require('fs');
const rl = readline.createInterface({
input: fs.createReadStream('sample.txt')
});
rl.on('line', function (line) {
console.log('Line from file:', line);
});
## readline.clearLine(stream, dir)
Clears current line of given TTY stream in a specified direction.

Loading…
Cancel
Save