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: #4609
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>>
  • Loading branch information
eljefedelrodeodeljefe authored and Myles Borins committed Jan 12, 2016
1 parent 787c5d9 commit 3912b5c
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 3912b5c

Please sign in to comment.