And using the difference between the node in the linux environment variables, bash_profile, bashrc, bash_history, bash_logout

View the environment variables

# 查看全部环境变量
env
# 查看某一个
echo $PATH

Set Environment Variables

# 新增环境变量
export http_proxy=http://127.0.0.1:8080/
# 删除环境变量
unset http_proxy

For the first time to see the home directory has no .bash_profiledocuments, not just to create one, in order to use those commands. After changing this file using source ~/.bash_profilecommands to validate the configuration

The user level ~/.bash_profile ~/.bashrc ~/.bash_historyand ~/.bash_logoutthe difference between files

The above three documents is bash shell profile user environment, under the user's home directory.
~/.bash_profile: The most important is a configuration file that is read each time a user login system, all commands will be executed inside the bash.
~/.bashrc: When reading will invoke another bash shell in the bash shell, that is, and then type the command in a shell bash will read the file when you start a new shell. This can effectively isolate the desired login and sub-shell environment. But in general it will be called .bashrc .bash_profile script in order to harmonize configure the user environment.
~/.bash_history: Which records all the commands you type in the bash shell.
~/.bash_logout: Read when you exit the shell. So we can put some commands to clean up our work on this file.

System level /etc/bashrc /etc/profiledifference file

When not found in the user's home directory ~/.bash_profile, and ~/.bashrcwhen, will read both files.

Use environment variables in the node

We often use such a service start node:

// linux中
NODE_ENV=test node app.js
// windows中
set NODE_ENV=test
node app
// 使用 cross-env
npm i cross-env -g
cross-env NODE_ENV=test node app
// 直接在代码中设置环境变量
process.env.NODE_ENV = 'production'

Through the above command to start the program, specify the current value of the environment variable NODE_ENV test, then the environment variable can be obtained by process.env in app.js in:

console.log(process.env.NODE_ENV)
// test
发布了165 篇原创文章 · 获赞 59 · 访问量 3万+

Guess you like

Origin blog.csdn.net/weixin_43972437/article/details/104002283