diff --git a/doc/api/readline.markdown b/doc/api/readline.markdown index 05a52cd25cc390..a83b492b0b5621 100644 --- a/doc/api/readline.markdown +++ b/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.