Skip to content

Commit

Permalink
doc: adds usage of readline line-by-line parsing
Browse files Browse the repository at this point in the history
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: nodejs#4609
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: James M Snell <[email protected]>>
  • Loading branch information
eljefedelrodeodeljefe authored and Michael Scovetta committed Apr 2, 2016
1 parent 2ddfe51 commit 7f51e15
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/api/readline.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7f51e15

Please sign in to comment.