We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
讲config之前,先说一下环境变量这个事。
Linux系统中查看所有环境变量
env
node中常用到的环境变量是NODE_ENV,查看是否存在
echo $NODE_ENV
Linux系统中添加环境变量
某些时候需要删除环境变量
unset NODE_ENV
环境变量追加值
export PATH=$PATH:/home/download:/usr/local/
安装
npm install config
代码中使用
config安装成功后,可以在项目中创建几种环境的配置文件。
{ "port": 9001, "host": "http://localhost:9001", "redis":{ "host": "localhost", "port": 6379, "password":"root", "db": 2, "connectTimeout": 3000, "prefix": "koala:" } }
代码中使用配置文件
const config=require('config'); app.use(require('./middleware/redis')(config.get('redis')));
开启app服务
export NODE_ENV=development node app.js
export NODE_ENV='development' && node app.js ```linux - pm2指定名称与环境启动app服务 ```linux pm2 start app.js --env development --name koala
--name name指的是pm2指定的进程名称。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
环境变量
讲config之前,先说一下环境变量这个事。
Linux系统中查看所有环境变量
node中常用到的环境变量是NODE_ENV,查看是否存在
Linux系统中添加环境变量
某些时候需要删除环境变量
环境变量追加值
config模块包使用
安装
代码中使用
config安装成功后,可以在项目中创建几种环境的配置文件。
以development环境举例:
代码中使用配置文件
开启app服务
--name name指的是pm2指定的进程名称。
The text was updated successfully, but these errors were encountered: