to extend the environment variables for a child process, the environment of the parent should be duplicated, and then extended, as follows
How to Optimize CPU-Intensive Work in Node.js
Graeme
12212

Another way of creating an extended copy of an Object, which I quite like, is using Object.assign.

Sharing as you might like this approach as well.

var child_process = require('child_process');
// Duplicate the parent's environment object
// and extend this with some new variables:
var envDup = Object.assign({}, process.env, {
'VAR NAME': 'var value'
});
// Run child process with these environment variables
child_process.exec('ls', { env: envDup }, function(err, stdout, stderr) {
if (err) {
throw err;
}
console.log(stdout);
});
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.