Skip to content

process.stdin seems to fail to populate the internal buffer #43918

Answered by gh-andre
gh-andre asked this question in General
Discussion options

You must be logged in to vote

I did some debugging and turns out that the internal stream read buffer is indeed not populated initially, even if there is data in the input. The implementation is such that the readable event must be used it has nothing to do with the readable state indicator. In fact, the latter just indicates that the stream hasn't gone bad.

The example from the docs is the only way to read from process.stdin via read().

console.log("isPaused(): " + process.stdin.isPaused());
console.log("readable: " + process.stdin.readable);
console.log("readableFlowing: " + process.stdin.readableFlowing);

process.stdin.on("readable", () => {
  let chunk = process.stdin.read();

  if(chunk)
    console.log("chunk: " +

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gh-andre
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant