isTTY can be used to tailor appropriate Node process output
Written by Stefan Judis
- Published at
- Updated at
- Reading time
- 1min
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. :)

If you enjoyed this article...
Join 6.3k readers and learn something new every week with Web Weekly.
Reply to this post and share your thoughts via good old email.
