Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
docs: clarify process.stdin and old mode
Browse files Browse the repository at this point in the history
  • Loading branch information
subzey authored and tjfontaine committed Feb 18, 2014
1 parent 1d734a7 commit 1fa5cff
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions doc/api/process.markdown
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -164,22 +164,34 @@ that writes to them are usually blocking.


## process.stdin ## process.stdin


A `Readable Stream` for stdin. The stdin stream is paused by default, so one A `Readable Stream` for stdin.
must call `process.stdin.resume()` to read from it.


Example of opening standard input and listening for both events: Example of opening standard input and listening for both events:


process.stdin.resume();
process.stdin.setEncoding('utf8'); process.stdin.setEncoding('utf8');


process.stdin.on('data', function(chunk) { process.stdin.on('readable', function(chunk) {
process.stdout.write('data: ' + chunk); var chunk = process.stdin.read();
if (chunk !== null) {
process.stdout.write('data: ' + chunk);
}
}); });


process.stdin.on('end', function() { process.stdin.on('end', function() {
process.stdout.write('end'); process.stdout.write('end');
}); });


As a Stream, `process.stdin` can also be used in "old" mode that is compatible
with scripts written for node prior v0.10.
For more information see
[Stream compatibility](stream.html#stream_compatibility_with_older_node_versions).

In "old" Streams mode the stdin stream is paused by default, so one
must call `process.stdin.resume()` to read from it. Note also that calling
`process.stdin.resume()` itself would switch stream to "old" mode.

If you are starting a new project you should prefer a more recent "new" Streams
mode over "old" one.


## process.argv ## process.argv


Expand Down

0 comments on commit 1fa5cff

Please sign in to comment.