Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3912b5c

Browse filesBrowse files
eljefedelrodeodeljefeMyles Borins
authored andcommitted
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: #4609 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: James M Snell <jasnell@gmail.com>>
1 parent 787c5d9 commit 3912b5c
Copy full SHA for 3912b5c

File tree

Expand file treeCollapse file tree

1 file changed

+16
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/readline.markdown‎

Copy file name to clipboardExpand all lines: doc/api/readline.markdown
+16Lines changed: 16 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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+
A common case for `readline`'s `input` option is to pass a filesystem readable
238+
stream to it. This is how one could craft line-by-line parsing of a file:
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.