Skip to content

Commit 1fa5cff

Browse files
subzeytjfontaine
authored andcommitted
docs: clarify process.stdin and old mode
1 parent 1d734a7 commit 1fa5cff

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

doc/api/process.markdown

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,34 @@ that writes to them are usually blocking.
164164

165165
## process.stdin
166166

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

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

172-
process.stdin.resume();
173171
process.stdin.setEncoding('utf8');
174172

175-
process.stdin.on('data', function(chunk) {
176-
process.stdout.write('data: ' + chunk);
173+
process.stdin.on('readable', function(chunk) {
174+
var chunk = process.stdin.read();
175+
if (chunk !== null) {
176+
process.stdout.write('data: ' + chunk);
177+
}
177178
});
178179

179180
process.stdin.on('end', function() {
180181
process.stdout.write('end');
181182
});
182183

184+
As a Stream, `process.stdin` can also be used in "old" mode that is compatible
185+
with scripts written for node prior v0.10.
186+
For more information see
187+
[Stream compatibility](stream.html#stream_compatibility_with_older_node_versions).
188+
189+
In "old" Streams mode the stdin stream is paused by default, so one
190+
must call `process.stdin.resume()` to read from it. Note also that calling
191+
`process.stdin.resume()` itself would switch stream to "old" mode.
192+
193+
If you are starting a new project you should prefer a more recent "new" Streams
194+
mode over "old" one.
183195

184196
## process.argv
185197

0 commit comments

Comments
 (0)