Is there a way to set the NODE_PATH env variable after node has started?
if I do this:
async.series([
function export_NODE_PATH(cb){
cp.exec('export NODE_PATH=$(npm root -g):$NODE_PATH',cb);
},...
it won't work, but if I set NODE_PATH before starting node, it will work as expected
export NODE_PATH=$(npm root -g):$NODE_PATH && node index --transpile test
is there a way to set the environment variable in the node.js runtime, without the need to set it at the command line before executing? Is it as simple as setting process.env.NODE_PATH during runtime?
For example, this seems to work:
cp.exec('echo $(npm root -g)', function (err, stdout, stderr) {
if (err || String(stdout).match(/error/i) || String(stderr).match(/error/i)) {
cb(err || stdout || stderr); // my funky way of handling this
}
else {
process.env.NODE_PATH += stdout;
cb(null);
}
});
but I don't know how kosher that is, and it does not actually seem to work, after further testing.