NO_COLOR and FORCE_COLOR precedence

I understand that according to the python docs, the NO_COLOR environment variable takes precedence over FORCE_COLOR, but the behaviour is opposite in, say, node.js. Is this a difference in convention?

You would need more examples to show a convention I think.

I don’t think Node.js itself uses colour, but there are libraries that do.

For example with this package.json:

{
  "type": "module",
  "dependencies": {
    "picocolors": "^1.1.1"
  }
}

This demo.js:

import pc from 'picocolors';
console.log(pc.green('Hello, world!'));

Then npm install and run node demo.js, and prefix with FORCE_COLOR=1 and/or NO_COLOR=1:

NO_COLOR=1 overrides FORCE_COLOR=1 as expected.

See no-color.org and force-color.org.

According to the example implementation on force-color.org, FORCE_COLOR=1 overrides NO_COLOR=1, since it’s applied after NO_COLOR.

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char *argv[])
{
    char *no_color = getenv("NO_COLOR");
    char *force_color = getenv("FORCE_COLOR");
    bool color = true;

    if (no_color != NULL && no_color[0] != '\0')
        color = false;

    /* do getopt(3) and/or config-file parsing */

    if (force_color != NULL && force_color[0] != '\0')
        color = true;

    printf("color = %d\n", color);
}
$ cc foo.c
$ NO_COLOR=1 FORCE_COLOR=1 ./a.out
color = 1