Rather than setting the env var for the process, you can set it on a per-command basis via the options object to exec() / spawn().

Might simplify your logic to make use of superspawn.js helper class, which makes it easier to merge environment variables.