and what is this command actually doing?
export VAR="My permanent variable"
I used this and was able to see that it was set by doing a:
printenv VAR
However, when I console.log(process.env) in Node I can not find it. Here is the ouptut:
{
USER: 'c',
__CFBundleIdentifier: 'com.sublimetext.4',
COMMAND_MODE: 'unix2003',
LOGNAME: 'c',
PATH: '/Applications/Sublime Text.app/Contents/SharedSupport/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin',
SSH_AUTH_SOCK: '/private/tmp/com.apple.launchd.jc2uZOHY77/Listeners',
SHELL: '/bin/zsh',
HOME: '/Users/c',
__CF_USER_TEXT_ENCODING: '0x1F5:0x0:0x0',
TMPDIR: '/var/folders/tx/zyf0hzln2rn97yd61x50y9l80000gn/T/',
XPC_SERVICE_NAME: '0',
XPC_FLAGS: '0x0',
LC_CTYPE: 'UTF-8',
SSL_CERT_FILE: '/Applications/Sublime Text.app/Contents/MacOS/Lib/python3/certifi/cacert.pem',
OLDPWD: '/'
}
I would like to set the process.env.VAR directly in the bash/zsh ( I am using zshell.) and have access to it in my Node code.
It set env variable, however not persistent manner.
If you do
export MY_VAR=123 && node index.js
Assuming index.js will have console.log(process.env) you will get the output. But in different terminal windows it won't be visible/shared. To achieve that you need to add export VAR=value in .bashrc file
and reload the content. (It means every time a new terminal is open it will set that value)
Since you use zshell it will be .zshrc.
nano ~/.zshrcexport YOUR_VAR=your_valuezsh or reopen terminalHere are more details on how to do it for zsh. link