From 96618cf282391d350c4a23f9cdc8989084f8c79d Mon Sep 17 00:00:00 2001 From: Abhimanyu Date: Tue, 10 Mar 2026 11:37:00 +0530 Subject: [PATCH] fix: respect NO_COLOR environment variable When NO_COLOR=1 is set, disable colored output in dev format to comply with no-color.org standard (morgan#302) --- index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index bb97912..a2169ef 100644 --- a/index.js +++ b/index.js @@ -186,12 +186,13 @@ morgan.format('dev', function developmentFormatLine (tokens, req, res) { ? res.statusCode : undefined - // get status color - var color = status >= 500 ? 31 // red - : status >= 400 ? 33 // yellow - : status >= 300 ? 36 // cyan - : status >= 200 ? 32 // green - : 0 // no color + // get status color (disabled if NO_COLOR is set) + var color = process.env.NO_COLOR ? 0 + : status >= 500 ? 31 // red + : status >= 400 ? 33 // yellow + : status >= 300 ? 36 // cyan + : status >= 200 ? 32 // green + : 0 // no color // get colored function var fn = developmentFormatLine[color]