首页 > 解决方案 > 如何使用 Nodejs 访问 Google App Engine 上的 process.env

问题描述

我在谷歌应用引擎上使用反应。

正如文档中所写:https ://cloud.google.com/appengine/docs/standard/nodejs/runtime#environment_variables

我可以访问以下环境变量:

Environment variable    Description
GAE_APPLICATION The ID of your App Engine application.
GAE_DEPLOYMENT_ID   The ID of the current deployment.
GAE_ENV The App Engine environment. Set to standard.
GAE_INSTANCE    The ID of the instance on which your service is currently running.
GAE_MEMORY_MB   The amount of memory available to the application process, in MB.
GAE_RUNTIME The runtime specified in your app.yaml file.
GAE_SERVICE The service name specified in your app.yaml file. If no service name is specified, it is set to default.
GAE_VERSION The current version label of your service.
GOOGLE_CLOUD_PROJECT    The GCP project ID associated with your application.
NODE_ENV    Set to production when your service is deployed.
PORT    The port that receives HTTP requests.

当我在 google app engine 上部署我的应用程序并打印 process.env console.log(process.env) 我只有:

NODE_ENV: "production"
PUBLIC_URL: ""

在文档中明确写了“以下环境变量由运行时设置”,但其中没有一个。

怎么了?

标签: node.jsgoogle-app-engine

解决方案


“以下环境变量由运行时设置”的含义适用于由node. 因此,process.env从 express.js 应用程序运行时打印的内容包含这些环境变量,因为您将执行代码,node .bin/wwwnode server.js不是react-scripts start在部署 react.js 应用程序时。在这种情况下,由 create-react-app 负责设置环境变量。或者,您可以根据规范手动设置这些环境变量。create-react-app


推荐阅读