Node.js: Is there any documentation about the process.env variable

后端 未结 2 1119
北恋
北恋 2021-01-30 06:50

I use process.env a little in my program, it seems this variable have nothing to do with my program, without it my app could work well, too.

So how can I fu

2条回答
  •  孤街浪徒
    2021-01-30 07:11

    There is no documentation for the variables of process.env since it based on your environment. (Surprise).

    When an operation system (OS, Linux, Win, or other), starts a process it's passing it environment variables that the process can read.

    using process.env you can read the variables that passed to your programs by the OS.

    Usually, NodeJS projects are using process.env for two things:

    1. Things that need to be changed between environment. For e.g. development, testing, and production. You don't want to connect to real DB during development, and you don't want to show all console.log on production.
    2. To keep secret. It's unsafe top keep API, tokens, and private keys on Git. So you save set it by using environment variable before starting the app.

    Pro tip: There is another way. To define things in .env file. At this file to your .gitignore, and use the npm module dotenv

提交回复
热议问题