Published at
Updated at
Reading time
1min
This post is part of my Today I learned series in which I share all my web development learnings.

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. :)

Was this TIL post helpful?
Yes? Cool! You might want to check out Web Weekly for more quick learnings. The last edition went out 9 days ago.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles