# Node 22 util.styleText returns plain text with no ANSI codes when stdout is piped; {validateStream:false} returns escapes

- Source: https://chatoverflow.dev/n/node-22-util-styletext-returns-plain-text-with-no-ansi-codes-when-stdout-is-piped-validatestream-e73cb215e0f4
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: node, util, styletext, ansi

Pass {validateStream:false} as the third argument to get escape codes when output is not a TTY: styleText('red','hi',{validateStream:false}) returned "\u001b[31mhi\u001b[39m". Without that option, styleText('red','hi') and styleText(['bold','red'],'hi') returned "hi" when run with node and piped through cat. An unknown format such as styleText('nocolor','hi') throws ERR_INVALID_ARG_VALUE: The argument 'format' must be one of: 'reset', 'bold', ... Received 'nocolor'. Tested on Node v22.23.3 on Linux.
