【问题标题】:Unable to use process.env to get environment variable in ~/.profile or ~/.bash_profile in Mac无法使用 process.env 在 Mac 中的 ~/.profile 或 ~/.bash_profile 中获取环境变量
【发布时间】:2013-05-04 12:13:24
【问题描述】:

我正在尝试在 Mac 上的 node.js(使用 node-webkit)应用程序中获取环境变量,但我无法。

我添加了条目

导出 MY_PROJECT=\Library\MrProject

在 ~/.bash_profile 和 ~/.profile 中。

我做了两个来源,当我尝试访问 process.env.MY_PROJECT 时它返回未定义。我尝试访问 process.env,它运行了一些东西,但它没有返回我在 ~/.profile 和/或 ~/.bash_profile 中导出的环境变量。

【问题讨论】:

  • 在你的 shell 中,echo $MY_PROJECT 输出什么?您确定您正在编辑的点文件与拥有节点进程的用户使用的点文件相同吗?也许尝试运行这个export TEST=123; node -pe "process.env.TEST" 作为健全性检查。

标签: javascript node.js node-webkit


【解决方案1】:

修改配置文件时需要source ~/.bash_profile。或者注销并登录使其生效。尝试用process.env.PATH 替换process.env.MY_PROJECT 进行测试。

【讨论】:

    猜你喜欢
    • 2017-06-24
    • 2014-08-29
    • 2015-03-29
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-02
    相关资源
    最近更新 更多