如何为不同的环境阶段自定义Node.js .env文件

by Erisan Olasheni

由Erisan Olasheni

如何为不同的环境阶段自定义Node.js .env文件 (How to customize Node.js .env files for different environment stages)

Have you ever found yourself in a situation where you needed custom environment variables for different development stages of your app? Here is a one-line solution.

您是否曾经遇到过需要在应用程序的不同开发阶段使用自定义环境变量的情况? 这是一线解决方案。

Development has been much easier since the invention of the .env file. You can easily set your environment variables and values with the syntax ENV_VARIABLE=VALUE and boom! These variables got loaded as your environment variables, making it possible to get quick access to them:

自发明.env文件以来,开发工作变得更加容易。 您可以使用语法ENV_VARIABLE=VALUE轻松设置环境变量和值,然后开始! 这些变量已作为环境变量加载,从而可以快速访问它们:

console.log(process.env.ENV_VARIABLE)

In case you are still wondering what all this means, well, you are probably new to the .env file. It’s actually a simple configuration text file that is used to define some variables you want to pass into your application’s environment.

如果您仍然想知道这一切意味着什么,那么,您可能是.env文件的.env 。 它实际上是一个简单的配置文本文件,用于定义一些要传递到应用程序环境中的变量。

This file needs a something like a parser to make it work. The parser reads the variable definitions one-by-one and parses them to the environment. It uses the format ENV_VARIABLE=VALUE (in the case of Node.js:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值