Node.js: How to disable colors in the console?
Asked Answered
N

3

7

Im new to node.js and are currently playing around with npm.

I found that the console output is colored in a weird way on my System, i can only read it when i copypaste it into a text editor. Changing the background back to black and the font-color to white also did not help. Here is a screenshot:

Node.js colored console output unreadable

How can i disable those colors?

Nightwear answered 30/7, 2017 at 12:49 Comment(0)
B
12

Disable colors in npm using the next command:

npm config set color false

Alternatively, create a new script inside of your package.json with the next format:

  "scripts": {
    "install": "npm install --no-color"
  }

And use it like this from the command line:

npm run install --save <your_package>
Baku answered 30/7, 2017 at 12:59 Comment(3)
Added an update if that helps! Consider upvoting if the answer was useful to you :)Baku
here you have ;-)Nightwear
I have a command called "stage" and when I do "npm run stage --no-color" the switch did not have any effect. Am trying the config route now.Droll
L
2

The informal standard for color output suppression is the NO_COLOR environment variable set to a non-empty value. It should often help, and e.g. colorette supports it.

A very standard package in the Node ecosystem is supports-color, and it does not support NO_COLOR, though. Luckily, it can be forced to disable color output by setting the environment variable FORCE_COLOR to 0 (zero). Otherwise, among other approaches, it uses arguments sniffing for --color and --no-color, but relying on this is tricky. Using the environment variable is a sure way and it can even tunnel through NPM scripts that call NPM again, which would otherwise lose the --no-color argument.

Lemkul answered 12/6, 2024 at 8:45 Comment(0)
V
0

And if you are running docker you can add the NO_COLOR env varibale with any value at statup

for example

docker run -e NO_COLOR=true node:lts
Vanillic answered 8/2, 2024 at 14:11 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.