How to export env variable in node.js
One possible way is to use JS to print out the export statements, then in shell to use eval to evaluate it in the current shell.
e.g. test.js
#!/usr/bin/env node
console.log('export A=40; export B=10');
In the shell:
eval `./test.js`
echo $A
Node.js will run in an separate process which gets a copy of the environment. You cannot change the environment of you parent process (the one executing .bashrc).
But the following question has an answer for you: Can a shell script set environment variables of the calling shell?
You can write a new script file from within node.js and call it via source
.