Skip to content

support NO_COLOR environment variable in dev format#344

Open
SAY-5 wants to merge 1 commit intoexpressjs:masterfrom
SAY-5:fix/no-color-support
Open

support NO_COLOR environment variable in dev format#344
SAY-5 wants to merge 1 commit intoexpressjs:masterfrom
SAY-5:fix/no-color-support

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 15, 2026

The dev format now checks for the NO_COLOR environment variable
(https://no-color.org/) and omits ANSI escape codes when it is set.

When NO_COLOR is present in process.env, the dev format compiles a
plain-text format string without any \x1b[ sequences and caches it
under a separate 'nocolor' key so colored and uncolored output don't
interfere with each other.

Two new tests cover the behavior:

  • output contains no ANSI escape codes when NO_COLOR is set
  • output still includes the HTTP method and status code

Fixes #302

The dev format now checks for the NO_COLOR environment variable
(https://no-color.org/) and omits ANSI escape codes when it is set.
This follows the community convention adopted by many CLI tools.

Fixes expressjs#302
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

morgan('dev') does not respect NO_COLOR=1 environment variable

1 participant