Get environment variables from the shell
Especially useful for Electron apps as GUI apps on macOS doesn't inherit the environment variables defined in your dotfiles (.bash_profile/.zshrc/etc).
npm install shell-env
import {shellEnv} from 'shell-env';
console.log(await shellEnv());
//=> {TERM_PROGRAM: 'Apple_Terminal', SHELL: '/bin/zsh', ...}
console.log(await shellEnv('/bin/bash'));
//=> {TERM_PROGRAM: 'iTerm.app', SHELL: '/bin/zsh', ...}
[!NOTE] For Bash, it reads
.bash_profile, but not.bashrc.
[!NOTE] If your default shell is a non-POSIX shell (e.g., Nushell), it will fall back to
/bin/zshor/bin/bash.
Return a promise for the environment variables.
Returns the environment variables.
Type: string
Default: User default shell
Shell to read the environment variables from.