问题描述
我正在尝试按照教程进行操作,它说:
I'm trying to follow a tutorial and it says:
有几种方法可以加载凭据.
- 从环境变量加载,
- 从磁盘上的 JSON 文件加载,
密钥需要如下:
USER_ID, USER_KEY
...这意味着如果您正确设置了环境变量,您根本不需要在您的应用程序中管理凭据.
...This means that if you properly set your environment variables, you do not need to manage credentials in your application at all.
基于一些谷歌搜索,我似乎需要在 process.env
中设置变量?如何以及在哪里设置这些凭据?请举例.
Based on some Googling, it appears that I need to set the variables in process.env
? How and where do I set these credentials? Example Please.
推荐答案
环境变量(在本例中)用于将凭据传递给您的应用程序.USER_ID
和 USER_KEY
都可以分别从 process.env.USER_ID
和 process.env.USER_KEY
访问.您无需编辑它们,只需访问它们的内容即可.
Environment variables (in this case) are being used to pass credentials to your application. USER_ID
and USER_KEY
can both be accessed from process.env.USER_ID
and process.env.USER_KEY
respectively. You don't need to edit them, just access their contents.
看起来他们只是让您选择从 process.env
或某些特定文件加载您的 USER_ID
和 USER_KEY
盘.
It looks like they are simply giving you the choice between loading your USER_ID
and USER_KEY
from either process.env
or some specificed file on disk.
现在,当您运行应用程序时,奇迹就会发生.
Now, the magic happens when you run the application.
USER_ID=239482 USER_KEY=foobar node app.js
这将传递用户 ID 239482
和作为 foobar
的用户密钥.这适用于测试,但是对于生产,您可能会配置一些 bash 脚本来导出变量.
That will pass the user id 239482
and the user key as foobar
. This is suitable for testing, however for production, you will probably be configuring some bash scripts to export variables.
这篇关于为节点设置环境变量以检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!