process.stdout

process.stdout

A Writable Stream to stdout (on fd 1).

For example, a console.log equivalent could look like this:

console.log = (msg) => {
  process.stdout.write(`${msg}\n`);
};

process.stderr and process.stdout are unlike other streams in Node.js in that they cannot be closed (end() will throw), they never emit the 'finish' event and that writes can block when output is redirected to a file (although disks are fast and operating systems normally employ write-back caching so it should be a very rare occurrence indeed.)

To check if Node.js is being run in a TTY context, read the isTTY property on process.stderr, process.stdout, or process.stdin:

$ node -p "Boolean(process.stdin.isTTY)"
true
$ echo "foo" | node -p "Boolean(process.stdin.isTTY)"
false

$ node -p "Boolean(process.stdout.isTTY)"
true
$ node -p "Boolean(process.stdout.isTTY)" | cat
false

See the tty docs for more information.

doc_Nodejs
2016-04-30 04:41:22
Comments
Leave a Comment

Please login to continue.