1 Star 0 Fork 1

赵梓宇 / nodebestpractices

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
setnodeenv.md 1.69 KB
一键复制 编辑 原始数据 按行查看 历史
Kevyn Bruyere 提交于 2019-11-07 11:25 . Use simple quotes everywhere

Set NODE_ENV = production



One Paragraph Explainer

Process environment variables is a set of key-value pairs made available to any running program, usually for configuration purposes. Though any variables can be used, Node encourages the convention of using a variable called NODE_ENV to flag whether we’re in production right now. This determination allows components to provide better diagnostics during development, for example by disabling caching or emitting verbose log statements. Any modern deployment tool – Chef, Puppet, CloudFormation, others – support setting environment variables during deployment



Code example: Setting and reading the NODE_ENV environment variable

// Setting environment variables in bash before starting the node process
$ NODE_ENV=development
$ node
// Reading the environment variable using code
if (process.env.NODE_ENV === 'production')
    useCaching = true;



What Other Bloggers Say

From the blog dynatrace:

...In Node.js there is a convention to use a variable called NODE_ENV to set the current mode. We see that it, in fact, reads NODE_ENV and defaults to ‘development’ if it isn’t set. We clearly see that by setting NODE_ENV to production the number of requests Node.js can handle jumps by around two-thirds while the CPU usage even drops slightly. Let me emphasize this: Setting NODE_ENV to production makes your application 3 times faster!

NODE_ENV=production



马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhao-ziyu/nodebestpractices.git
git@gitee.com:zhao-ziyu/nodebestpractices.git
zhao-ziyu
nodebestpractices
nodebestpractices
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891