node.js - What exactly is node's env? What is the use?
怪我咯
怪我咯 2017-05-16 13:31:01
0
4
669

What does env of node mean as an environment variable? I’ve seen it in many places, but what’s the use?

Why didn’t I learn PHP with the concept of env before?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(4)
黄舟

Environment variables can be set through NODE_ENV (the default value is development). Run the following command in the terminal to get the debugging data of the development environment, such as logs, mongodb data operations, etc. Generally, we perform different processing on the development environment and production environment by checking this value. This value can be set on the command line in the following way:

linux & mac: export NODE_ENV=production
windows:set NODE_ENV=production
For example, if the code needs to do some processing in the production environment, you can write like this:

if (process.env.NODE_ENV === 'production') {
// just for production code
}

伊谢尔伦

php also has getenv putenv

迷茫

NODE_ENV is the environment variable of node.js and is part of the node.js module search. If it is not set, node.js will report a not found error after installing the global module

左手右手慢动作

For example, your code has a development (development) environment, a test (test) environment and an online (production-) environment. When you write code, you may develop it locally in the development environment first, then move to the test environment, and finally go online. How to control switching between different environments? This env is used at this time. According to the terminal's export NODE_ENV=test/NODE_ENV=development/NODE_ENV=production, you can get different environment variable parameters. Make different configurations based on these parameters, and then package them to get what you want. Production Environment.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!