1 # supports-color [![Build Status](https://travis-ci.org/chalk/supports-color.svg?branch=master)](https://travis-ci.org/chalk/supports-color)
3 > Detect whether a terminal supports color
9 $ npm install supports-color
16 const supportsColor = require('supports-color');
18 if (supportsColor.stdout) {
19 console.log('Terminal stdout supports color');
22 if (supportsColor.stdout.has256) {
23 console.log('Terminal stdout supports 256 colors');
26 if (supportsColor.stderr.has16m) {
27 console.log('Terminal stderr supports 16 million colors (truecolor)');
34 Returns an `Object` with a `stdout` and `stderr` property for testing either streams. Each property is an `Object`, or `false` if color is not supported.
36 The `stdout`/`stderr` objects specifies a level of support for color through a `.level` property and a corresponding flag:
38 - `.level = 1` and `.hasBasic = true`: Basic color support (16 colors)
39 - `.level = 2` and `.has256 = true`: 256 color support
40 - `.level = 3` and `.has16m = true`: Truecolor support (16 million colors)
45 It obeys the `--color` and `--no-color` CLI flags.
47 Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, add the environment variable `FORCE_COLOR=1` to forcefully enable color or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
49 Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
54 - [supports-color-cli](https://github.com/chalk/supports-color-cli) - CLI for this module
55 - [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
60 - [Sindre Sorhus](https://github.com/sindresorhus)
61 - [Josh Junon](https://github.com/qix-)