本文翻译自:Setting Environment Variables for Node to retrieve
I'm trying to follow a tutorial and it says:我正在尝试遵循一个教程,它说:
There are a few ways to load credentials.有几种加载凭据的方法。
Loaded from environment variables,从环境变量加载,
Loaded from a JSON file on disk,从磁盘上的JSON文件加载,
The keys need to be as follows:密钥需要如下:
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....这意味着,如果您正确设置环境变量,则根本不需要管理应用程序中的凭据。
Based on some Googling, it appears that I need to set the variables in process.env ?基于一些谷歌搜索,看来我需要在process.env设置变量?How and where do I set these credentials?如何以及在哪里设置这些凭据?Example Please.请举例。
It depends on your operating system and your shell这取决于您的操作系统和外壳
On linux with the shell bash , you create environment variables like this(in the console):在具有shell bash的linux上 ,您可以在控制台中创建如下这样的环境变量:
export FOO=bar
For more information on environment variables on ubuntu (for example):有关ubuntu上的环境变量的更多信息(例如):
Environment variables on ubuntuUbuntu上的环境变量
#3楼
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.USER_ID和USER_KEY都可以分别从process.env.USER_ID和process.env.USER_KEY访问。You don't need to edit them, just access their contents.您无需编辑它们,只需访问它们的内容即可。
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.看起来他们只是在为您USER_KEY从process.env或磁盘上某些特定文件加载USER_ID和USER_KEY之间进行选择的选择。
Now, the magic happens when you run the application.现在,当您运行应用程序时,魔术就发生了。
USER_ID=239482 USER_KEY=foobar node app.js
That will pass the user id 239482 and the user key as foobar .这将传递用户ID 239482和用户密钥foobar 。This is suitable for testing, however for production, you will probably be configuring some bash scripts to export variables.这适用于测试,但是对于生产而言,您可能会配置一些bash脚本以导出变量。
#4楼
只需在命令行上提供环境值
USER_ID='abc' USER_KEY='def' node app.js
#5楼
For windows users this Stack Overflow question and top answer is quite useful on how to set environement variables via the command line对于Windows用户,此Stack Overflow问题和最佳答案对于如何通过命令行设置环境变量非常有用。
How can i set NODE_ENV=production in Windows?如何在Windows中设置NODE_ENV = production?
#6楼
If you want a management option, try the envs npm package.如果需要管理选项,请尝试使用envs npm软件包。It returns environment values if they are set.如果设置了环境值,它将返回。Otherwise, you can specify a default value that is stored in a global defaults object variable if it is not in your environment.否则,您可以指定默认值,如果该默认值不在您的环境中,则该默认值存储在全局默认对象变量中。
Using .env ("dot ee-en-vee") or environment files is good for many reasons.使用.env (“ dot ee-en-vee”)或环境文件有很多好处。Individuals may manage their own configs.个人可以管理自己的配置。You can deploy different environments (dev, stage, prod) to cloud services with their own environment settings.您可以使用自己的环境设置将不同的环境(开发,阶段,产品)部署到云服务。And you can set sensible defaults.您可以设置合理的默认值。
Inside your .env file each line is an entry, like this example:在您的.env文件中,每一行都是一个条目,例如以下示例:
You should not include the .env in your version control repository (add it to your .gitignore file).你不应该包括.env在版本控制库(它添加到你.gitignore文件)。
To get variables from the .env file into your environment, you can use a bash script to do the equivalent of export NODE_ENV=development right before you start your application.要将变量从.env文件获取到您的环境中,可以在启动应用程序之前使用bash脚本执行相当于export NODE_ENV=development 。
#!/bin/bash
while read line; do export "$line";
done
Then this goes in your application javascript:然后这进入您的应用程序javascript:
var envs = require('envs');
// If NODE_ENV is not set,
// then this application will assume it's prod by default.
app.set('environment', envs('NODE_ENV', 'production'));
// Usage examples:
app.set('ga_account', envs('GA_UA'));
app.set('nr_browser_key', envs('NEW_RELIC_BROWSER_KEY'));
app.set('other', envs('SOME_OTHER_TOKEN));
同生成的做法一样,添加和移除类成员只要去修改fields和methods中的元素即可。这里我们拿一个简单的类做例子,下面这个Task类,我们来移除isNeedRemove方法,并且添加一个int 类型的addedField属性。
package asm.core;
/**
* Created by yunshen.ljy on 2015/6/
交换两个数字的方法有以下三种 ,其中第一种最常用
/*
输出最小的一个数
*/
public class jiaohuan1 {
public static void main(String[] args) {
int a =4;
int b = 3;
if(a<b){
// 第一种交换方式
int tmep =
1. Kafka提供了两种Consumer API
High Level Consumer API
Low Level Consumer API(Kafka诡异的称之为Simple Consumer API,实际上非常复杂)
在选用哪种Consumer API时,首先要弄清楚这两种API的工作原理,能做什么不能做什么,能做的话怎么做的以及用的时候,有哪些可能的问题
CompositeChannelBuffer体现了Netty的“Transparent Zero Copy”
查看API(
http://docs.jboss.org/netty/3.2/api/org/jboss/netty/buffer/package-summary.html#package_description)
可以看到,所谓“Transparent Zero Copy”是通
// this need android:minSdkVersion="11"
getActionBar().setDisplayHomeAsUpEnabled(true);
@Override
public boolean onOptionsItemSelected(MenuItem item) {
$(document).ready(function () {
var request = {
QueryString :
function (val) {
var uri = window.location.search;
var re = new RegExp("" + val + "=([^&?]*)", &
ArticleSelect类在命名空间HoverTree.Model中可以认为是文章查询条件类,用于存放查询文章时的条件,例如HvtId就是文章的id。HvtIsShow就是文章的显示属性,当为-1是,该条件不产生作用,当为0时,查询不公开显示的文章,当为1时查询公开显示的文章。HvtIsHome则为是否在首页显示。HoverTree系统源码完全开放,开发环境为Visual Studio 2013
1. php 类
I found this class looking for something else actually but I remembered I needed some while ago something similar and I never found one. I'm sure it will help a lot of developers who try to
Design pattern for graph processing.
Since we consider a large number of graph-processing algorithms, our initial design goal is to decouple our implementations from the graph representation