fix: respect NO_COLOR environment variable in dev format#341
Open
mahmoodhamdi wants to merge 1 commit intoexpressjs:masterfrom
Open
fix: respect NO_COLOR environment variable in dev format#341mahmoodhamdi wants to merge 1 commit intoexpressjs:masterfrom
mahmoodhamdi wants to merge 1 commit intoexpressjs:masterfrom
Conversation
The dev format uses ANSI color codes to colorize status codes, but did not respect the NO_COLOR environment variable, which is the widely-accepted standard for disabling color output in CLI tools (see https://no-color.org). When NO_COLOR is set, the dev format now outputs plain text without any ANSI escape sequences, improving accessibility for users with limited vision or environments where color codes cause issues. Fixes expressjs#302
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
devformat now respects theNO_COLORenvironment variable by omitting ANSI escape codes when it is set.Problem
The
devformat uses ANSI color codes to colorize HTTP status codes (green for 2xx, cyan for 3xx, yellow for 4xx, red for 5xx). However, it does not respect theNO_COLORenvironment variable, which is the widely-accepted standard for disabling color output in terminal applications.This causes accessibility issues for users with limited vision and problems in environments where ANSI escape codes are not supported or cause garbled output (CI logs, file redirection, etc.).
Fix
When
NO_COLORis set inprocess.env, thedevformat outputs plain text without any ANSI escape sequences:Instead of:
The no-color format is cached separately from colored formats, so there is no performance impact.
Testing
Added a test that verifies the output contains no ANSI escape codes when
NO_COLORis set. All 83 tests pass. Lint clean.Fixes #302