2013-02-25 73 views

回答

67

嘗試此鏈接http://nodejs.org/api/process.html#process_process_env

然後你就可以在的NodeJS一個小程序:

console.log(process.env) 

並運行它

$ node myProgram.js 

{ TERM_PROGRAM: 'iTerm.app', 
    TERM: 'xterm', 
    SHELL: '/bin/bash', 
    CLICOLOR: '1', 
    TMPDIR: '/var/folders/ff/59np25p96x95hpgbtsv3r6zr0000gn/T/', 
    Apple_PubSub_Socket_Render: '/tmp/launch-LIiu0r/Render', 
    OLDPWD: '/Users/hermanjunge', 
    USER: 'hermanjunge', 
    COMMAND_MODE: 'unix2003', 
    SSH_AUTH_SOCK: '/tmp/launch-XOMy7j/Listeners', 
    __CF_USER_TEXT_ENCODING: '0x1F5:0:0', 
    Apple_Ubiquity_Message: '/tmp/launch-jiZQH0/Apple_Ubiquity_Message', 
    LSCOLORS: 'ExFxCxDxBxegedabagacad', 
    PATH: '/Users/hermanjunge/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/usr/local/mysql/bin', 
    PWD: '/tmp', 
    ITERM_PROFILE: 'hermanjunge', 
    SHLVL: '1', 
    COLORFGBG: '7;0', 
    HOME: '/Users/hermanjunge', 
    ITERM_SESSION_ID: 'w1t4p0', 
    LOGNAME: 'hermanjunge', 
    LC_CTYPE: 'UTF-8', 
    DISPLAY: '/tmp/launch-HCtQeC/org.macosforge.xquartz:0', 
    _: '/usr/local/bin/node' } 

然後,我們瞭解到,我們可以從要素環境我們運行我們的應用程序。等等,例如:

console.log(process.env.PWD); 

它返回

/tmp 

等等......

+0

我可以添加或更改一些領域? – hh54188 2013-02-25 02:19:10

+14

用感興趣的變量運行你的程序。例如:'$ MYVAR = somevalue節點myProgram.js',然後通過它的名字訪問它:'console.log(process.env.MYVAR);' – 2013-02-25 02:20:42

+1

如果我想添加多個變量,我應該怎麼做?這樣的提示?我可以在哪裏學習? – hh54188 2013-02-25 02:30:51

相關問題