Skip to content

Commit 89b2254

Browse files
docs: 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: #4609 Reviewed-By:
1 parent adf41b9 commit 89b2254

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

doc/api/readline.markdown

+16
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,22 @@ line interface:
232232
process.exit(0);
233233
});
234234

235+
## Example: Read File Stream Line-by-Line
236+
237+
Also a common case for `readline`'s `input` option is passing a file system
238+
readable Stream to it. This is how one could craft line-by-line parsing:
239+
240+
const readline = require('readline');
241+
const fs = require('fs');
242+
243+
const rl = readline.createInterface({
244+
input: fs.createReadStream('sample.txt')
245+
});
246+
247+
rl.on('line', function (line) {
248+
console.log('Line from file:', line);
249+
});
250+
235251
## readline.clearLine(stream, dir)
236252

237253
Clears current line of given TTY stream in a specified direction.

0 commit comments

Comments
 (0)