npm config Use

Environment Variables

Speaking before the config, the first thing to say about this environment variable.

See all Linux system environment variables

env
复制代码

node used to the environment variable is NODE_ENV, see if there are

echo $NODE_ENV
复制代码

Linux system environment variables added

env
复制代码

Sometimes you need to remove an environment variable

unset NODE_ENV
复制代码

Environment variables added value

export PATH=$PATH:/home/download:/usr/local/
复制代码

config module package using

installation

npm install config

复制代码

Use code

Config After a successful installation, you can create several environmental profile in the project.

  1. test test environment
  2. product production environment
  3. development development environment to development environment, for example:
{
  "port": 9001,
  "host": "http://localhost:9001",
  "redis":{
    "host": "localhost",
    "port": 6379,
    "password":"root",
    "db": 2,
    "connectTimeout": 3000,
    "prefix": "koala:"
  }
 }
复制代码

Code using a configuration file

const config=require('config');

app.use(require('./middleware/redis')(config.get('redis')));

复制代码

Open the app service

  • General Startup
export NODE_ENV=development
node app.js
复制代码
  • A command to start the app server
export NODE_ENV='development' && node app.js
```linux
- pm2指定名称与环境启动app服务

```linux
pm2 start app.js --env development --name koala
复制代码

--name name refers pm2 specified process name.

The end of the promotion

I think this paper help you? Please share with more people

Welcome to my public concern number - programmers growth refers to the North. Your own micro-letter search - "Programmer growth refers to the North."

Previous article: How to Write an elegant native SQL statements?

Guess you like

Origin blog.csdn.net/weixin_34025151/article/details/91400186