设置环境变量以供节点检索 [英] Setting Environment Variables for Node to retrieve

查看:63
本文介绍了设置环境变量以供节点检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循一个教程,它说:

I'm trying to follow a tutorial and it says:

有几种加载凭据的方法.

There are a few ways to load credentials.

  1. 从环境变量中加载
  2. 从磁盘上的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.

推荐答案

环境变量(在这种情况下)用于将凭据传递给您的应用程序.分别可以从process.env.USER_IDprocess.env.USER_KEY访问USER_IDUSER_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_IDUSER_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.

这篇关于设置环境变量以供节点检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆