isTTY can be used to tailor appropriate Node process output (#tilPost)

I was reading A Guide to Node.js Logging written by my colleague Dominik Kundel and found out that you can differentiate if a Node.js script runs in terminal mode or is piped into another process.
// script.js
console.log(process.st…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

I was reading A Guide to Node.js Logging written by my colleague Dominik Kundel and found out that you can differentiate if a Node.js script runs in terminal mode or is piped into another process.

// script.js
console.log(process.stdout.isTTY); 
// true when you run `node script.js`
// undefined when you run `node script.js > log.txt`

Using isTTY can avoid formatting, emojis or pretty colors when your script output goes to logging services or runs in CI.

To learn more check out the TTY docs or his article. :)


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate
APA
Stefan Judis | Sciencx (2022-12-09T06:10:44+00:00) » isTTY can be used to tailor appropriate Node process output (#tilPost). Retrieved from https://www.scien.cx/2019/05/17/istty-can-be-used-to-tailor-appropriate-node-process-output-tilpost/.
MLA
" » isTTY can be used to tailor appropriate Node process output (#tilPost)." Stefan Judis | Sciencx - Friday May 17, 2019, https://www.scien.cx/2019/05/17/istty-can-be-used-to-tailor-appropriate-node-process-output-tilpost/
HARVARD
Stefan Judis | Sciencx Friday May 17, 2019 » isTTY can be used to tailor appropriate Node process output (#tilPost)., viewed 2022-12-09T06:10:44+00:00,<https://www.scien.cx/2019/05/17/istty-can-be-used-to-tailor-appropriate-node-process-output-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » isTTY can be used to tailor appropriate Node process output (#tilPost). [Internet]. [Accessed 2022-12-09T06:10:44+00:00]. Available from: https://www.scien.cx/2019/05/17/istty-can-be-used-to-tailor-appropriate-node-process-output-tilpost/
CHICAGO
" » isTTY can be used to tailor appropriate Node process output (#tilPost)." Stefan Judis | Sciencx - Accessed 2022-12-09T06:10:44+00:00. https://www.scien.cx/2019/05/17/istty-can-be-used-to-tailor-appropriate-node-process-output-tilpost/
IEEE
" » isTTY can be used to tailor appropriate Node process output (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2019/05/17/istty-can-be-used-to-tailor-appropriate-node-process-output-tilpost/. [Accessed: 2022-12-09T06:10:44+00:00]
rf:citation
» isTTY can be used to tailor appropriate Node process output (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2019/05/17/istty-can-be-used-to-tailor-appropriate-node-process-output-tilpost/ | 2022-12-09T06:10:44+00:00
https://github.com/addpipe/simple-recorderjs-demo