我正在使用joi构建数据。
现在我无法读取启动时设置的环境变量。
我有一个启动 scrip.sh,如下所示:
PUBLIC_KEY="$(cat public_key.pem) docker-compose up --build"
然后我尝试读取该 PUBLIC_KEY
变量。
const envVariables = joi.object({
PUBLIC_KEY: joi.string()
.default('PUBLIC_KEY')
})
我以为这会自动识别变量,但事实并非如此。
是否可以在 Joi 启动时获取变量集?
最佳答案
您可以使用process
核心模块获取环境变量。来自 documentation :
The process core module of Node.js provides the env property which hosts all the environment variables that were set at the moment the process was started.
例如,
const pubKey = process.env.PUBLIC_KEY
关于javascript - 使用 JOI 获取环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70712407/