heroku 其他环境变量还有哪些?

问题描述 投票:0回答:5

在设置服务器时,我注意到使用了环境变量process.env.PORT。还有其他类似的变量吗?哪里可以看到全部?

web-services heroku environment-variables
5个回答
113
投票

以下命令将显示所有环境变量,而不仅仅是那些从

heroku config
中可见的变量:

heroku run printenv

14
投票

heroku config
不显示端口。因此,如果您需要一切,那么它是不完整的。这将创建一个一次性的测功机并显示一切。

从这里:https://devcenter.heroku.com/articles/getting-started-with-nodejs#console

在一次性测功机中运行控制台,然后在 > 提示符下输入“console.log(process.env)”:

$ heroku run node
Running `node` attached to terminal... up, run.4778
> console.log(process.env
... )
{ BUILDPACK_URL: 'https://github.com/MichaelJCole/heroku-buildpack-nodejs.git#wintersmith',
  TERM: 'xterm',
  SENDGRID_USERNAME: '[email protected]',
  COLUMNS: '80',
  DYNO: 'run.4778',
  PATH: '/app/bin:/app/node_modules/.bin:bin:node_modules/.bin:/usr/local/bin:/usr/bin:/bin',
  PWD: '/app',
  PS1: 'fairydust',
  LINES: '22',
  SHLVL: '1',
  HOME: '/app',
  SENDGRID_PASSWORD: 'ponies',
  PORT: '52031',
  _: '/app/bin/node' }
undefined

9
投票

命令是

heroku config

您可以在这里阅读更多内容https://devcenter.heroku.com/articles/config-vars


9
投票

参见 https://devcenter.heroku.com/articles/config-vars:有一个命令似乎可以告诉您环境变量是什么。

$ heroku config

看看这是否适合您。

编辑:上面链接的heroku文档似乎是错误的。试试这个:

$ heroku config -s --app <appname>

1
投票

这是我的 Node.JS 应用程序的 100% 环境变量。

heroku 上的文档对此非常糟糕。 你会期望他们有类似谷歌的东西 应用程序引擎参考有:

https://cloud.google.com/appengine/docs/standard/nodejs/runtime

但是,因为他们没有,我的解决方案就是创建 一个简单的“休息”端点,用于注销所有 环境变量。不要在严肃的应用程序中这样做。 相反,我会使用“Michael Cole”的日志记录方法。

请不要黑我。该项目在 2022 年 11 月之后将不存在,因为 heroku 将不再免费。所以我会冒险。目前正在将我的代码移植到“GoogleAppEngine”。

HEROKU_EXEC_URL : 
    https://exec-manager.heroku.com/370aa52e-ced2-4ad1-9db7-b11f98f8a7fd

DATABASE_URL ::::
    postgres://amrspwutkevecg:4958212525b67f2ee7a0f49c0c465f65da4c3e352880f5999f8ea6fac63a4cf5@ec2-34-200-35-222.compute-1.amazonaws.com:5432/ddb2djh5t66gqj

npm_config_user_agent :
    npm/8.19.2 node/v16.18.0 linux x64 workspaces/false

JAVA_TOOL_OPTIONS :  
    -Dcom.sun.management.jmxremote 
    -Dcom.sun.management.jmxremote.port=1098 
    -Dcom.sun.management.jmxremote.rmi.port=1099 
    -Dcom.sun.management.jmxremote.ssl=false 
    -Dcom.sun.management.jmxremote.authenticate=false 
    -Dcom.sun.management.jmxremote.local.only=true 
    -Djava.rmi.server.hostname=172.17.42.66 
    -Djava.rmi.server.port=1099

npm_node_execpath :
    /app/.heroku/node/bin/node

SHLVL : 0
npm_config_noproxy : <EMPTY STRING>
PORT : 19842
HOME : /app
npm_package_json : /app/package.json
PS1  : \[\033[01;34m\]\w\[\033[00m\] \[\033[01;32m\]$ \[\033[00m\]
npm_config_userconfig : /app/.npmrc
npm_config_local_prefix : /app
COLOR : 0
npm_config_metrics_registry : https://registry.npmjs.org/
_ : /app/.heroku/node/bin/npm
npm_config_prefix : /app/.heroku/node
WEB_CONCURRENCY : 1
npm_config_cache : /app/.npm
npm_config_node_gyp : /app/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js
PATH : /app/node_modules/.bin:/node_modules/.bin
     :/app/.heroku/node/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin
     :/app/.heroku/node/bin
     :/app/.heroku/yarn/bin
     :/usr/local/bin:/usr/bin
     :/bin:/app/bin:/app/node_modules/.bin
NODE :/app/.heroku/node/bin/node
MEMORY_AVAILABLE : 512
NODE_HOME : /app/.heroku/node
HEROKU_JMX_OPTIONS : 
    -Dcom.sun.management.jmxremote 
    -Dcom.sun.management.jmxremote.port=1098 
    -Dcom.sun.management.jmxremote.rmi.port=1099 
    -Dcom.sun.management.jmxremote.ssl=false 
    -Dcom.sun.management.jmxremote.authenticate=false 
    -Dcom.sun.management.jmxremote.local.only=true 
    -Djava.rmi.server.hostname=172.17.42.66 
    -Djava.rmi.server.port=1099

HEROKU_APP_ID : 265115d9-6eb1-4352-a83c-05b844ece512

npm_lifecycle_script : node ./ATOMIC_IVY_MMO.JS
npm_lifecycle_event  : start
npm_config_globalconfig : /app/.heroku/node/etc/npmrc
npm_config_init_module : /app/.npm-init.js
PWD : /app
npm_execpath : /app/.heroku/node/lib/node_modules/npm/bin/npm-cli.js
npm_config_global_prefix : /app/.heroku/node
npm_command : start
NODE_ENV : production
WEB_MEMORY : 512
DYNO : web.1
INIT_CWD : /app
EDITOR : vi

运行后添加的环境变量:

heroku labs:enable runtime-dyno-metadata -a <app name>

非标准,但可能很有用。特别是“HEROKU_APP_NAME” 您可以使用它来允许客户端应用程序发出 XMLHTTPRequests 到您服务器的 API。

HEROKU_APP_ID              unique identifier for the application.   
                           "9daa2797-e49b-4624-932f-ec3f9688e3da"
HEROKU_APP_NAME            application name.                        
                           "example-app"
HEROKU_DYNO_ID             dyno identifier. This metadata is not yet available in Private Spaces nor the Container Registry.    
                           "1vac4117-c29f-4312-521e-ba4d8638c1ac"
HEROKU_RELEASE_CREATED_AT  time and date the release was created.       
                           "2015-04-02T18:00:42Z"
HEROKU_RELEASE_VERSION     identifier for the current release.  
                           "v42"
HEROKU_SLUG_COMMIT         commit hash for the current release.     
                           "2c3a0b24069af49b3de35b8e8c26765c1dba9ff0"
HEROKU_SLUG_DESCRIPTION    description of the current release. 
                           "Deploy 2c3a0b2"

运行时元数据的文档: https://devcenter.heroku.com/articles/dyno-metadata

© www.soinside.com 2019 - 2024. All rights reserved.