From 3912b5cbdae0a7ceaa724404434a60d5981cd379 Mon Sep 17 00:00:00 2001 From: Robert Jefe Lindstaedt Date: Sun, 10 Jan 2016 17:18:49 +0100 Subject: [PATCH] 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 Reviewed-By: James M Snell > --- doc/api/readline.markdown | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/api/readline.markdown b/doc/api/readline.markdown index 05a52cd25c..a83b492b0b 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.