Skip to content

fix: respect NO_COLOR environment variable in dev format#360

Open
armorbreak001 wants to merge 1 commit into
expressjs:masterfrom
armorbreak001:fix/no-color-support
Open

fix: respect NO_COLOR environment variable in dev format#360
armorbreak001 wants to merge 1 commit into
expressjs:masterfrom
armorbreak001:fix/no-color-support

Conversation

@armorbreak001

Copy link
Copy Markdown

Problem

The dev format always outputs ANSI-colored text, ignoring the widely-adopted NO_COLOR environment variable (https://no-color.org/).

This causes accessibility issues for users with limited vision who may have difficulty reading colored terminal output.

Fix

When NO_COLOR is set (even to an empty string), the dev format outputs plain text without ANSI escape codes.

Changes

  • Modified the dev format function in index.js to check process.env.NO_COLOR
  • When set, compiles a plain-text format instead of a colored one
  • Cache key includes a -nc suffix to separate plain-text and colored compiled formats

Testing

  • All 88 existing tests pass
  • Manual test:
    NO_COLOR=1 node -e "require('./index.js')('dev')" | cat -v | grep '\\x1b'
    # Should return nothing (no ANSI codes)

Fixes #302

When the NO_COLOR environment variable is set (per https://no-color.org/),
the dev format now outputs plain text instead of ANSI-colored output.

This improves accessibility for users with limited vision who may
have difficulty reading colored terminal output.

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