Skip to content

fix: respect NO_COLOR environment variable in dev format - #353

Open
luisangelrod wants to merge 2 commits into
expressjs:masterfrom
luisangelrod:fix/no-color-env-var
Open

fix: respect NO_COLOR environment variable in dev format#353
luisangelrod wants to merge 2 commits into
expressjs:masterfrom
luisangelrod:fix/no-color-env-var

Conversation

@luisangelrod

@luisangelrod luisangelrod commented Jun 24, 2026

Copy link
Copy Markdown

Summary

The dev format currently emits ANSI color escape codes unconditionally. This change follows the NO_COLOR convention: color is disabled when NO_COLOR is present and non-empty, while an empty value preserves the existing behavior.

Changes

index.js

  • Check whether NO_COLOR has a non-empty value before compiling the dev format.
  • Cache a plain format without ANSI escape codes when color is disabled.
  • Preserve the current colored output when NO_COLOR is absent or empty.

test/morgan.js

  • Cover color-free 2xx and 5xx output with NO_COLOR=1.
  • Cover the convention's empty-value behavior.
  • Isolate the dev-format tests from an inherited NO_COLOR shell value and restore the original environment after each test.

Testing

  • npm test — 91 passing
  • npm run lint
  • git diff --check

Closes #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