[英]Is there a way to validate if all environment variables in the code exists in the .env file?
I'm trying to find a way to validate if all of the environment variables used in the code are actually set in the.env file我正在尝试找到一种方法来验证代码中使用的所有环境变量是否实际设置在 .env 文件中
Something like a test to run in the pipeline that throw a warning if I'm missing a variable in the environment I'm currently deploying.如果我在当前部署的环境中缺少变量,则类似于在管道中运行的测试会引发警告。
Context语境
Nodejs节点
It is a big application with a lot of environment variables.这是一个包含大量环境变量的大型应用程序。
There are multiple environments dev, qa, prod.有多个环境 dev、qa、prod。
I'm using the package dotenv我正在使用 package dotenv
dotenv.config()
process.env.A_VARIABLE
There is actually a package targeting exactly this issue: https://github.com/af/envalid实际上有一个 package 正是针对这个问题: https://github.com/af/envalid
You can define a required schema for the .env
file;您可以为.env
文件定义所需的架构; if a condition is not met, it will end the process with a proper error message.如果不满足条件,它将以适当的错误消息结束该过程。
Furthermore, there are nice features like providing default values and loading a sanitized and typesafe env object for further usage in your application.此外,还有一些不错的功能,例如提供默认值和加载经过清理和类型安全的环境 object 以便在您的应用程序中进一步使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.