Imagine we have a env.sh with following content.
export SOME_VAL="abcd"
We want to source this shell script from a JS (node.js) script bootstrap.js.
const childProcess = require('child_process');
const cmd = '. ' + pathToEnvScript;
childProcess.exec(cmd, (err, stdout, stderr) => {
    if (err) console.error(err);
    console.log(stdout);
})
Here is how we call the bootstrap.js.
echo $SOME_VAL # empty
node bootstrap.js
echo $SOME_VAL # empty
Why the sourcing doesn't take any effect? The sourcing works if we call source env.sh from terminal, but doesn't work for node bootstrap.js.



exportyour variables out of child scope.