简体   繁体   English

如何使用Node.js访问Google App Engine上的process.env

[英]How to access process.env on Google App Engine with Nodejs

I'm using react on google app engine. 我在Google App Engine上使用React。

As is written in the documentation: https://cloud.google.com/appengine/docs/standard/nodejs/runtime#environment_variables 如文档中所写: https : //cloud.google.com/appengine/docs/standard/nodejs/runtime#environment_variables

I can access the following Env Variable: 我可以访问以下环境变量:

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.

When I deploy my app on google app engine and print process.env console.log(process.env) I have only: 当我在Google App Engine上部署我的应用程序并打印process.env console.log(process.env)时,我只有:

NODE_ENV: "production"
PUBLIC_URL: ""

In the documentation is explicitly written "The following environment variables are set by the runtime", but there are no one of them. 在文档中明确地写了“以下环境变量由运行时设置”,但没有一个。

What is wrong? 怎么了?

What it means by "The following environment variables are set by the runtime" is applicable to applications executed by node . “以下环境变量由运行时设置”的含义适用于node执行的应用程序。 As such, the process.env printed when ran from an express.js application contains those environment variables because you would be executing your code as node .bin/www or node server.js as opposed to react-scripts start when deploying a react.js application. 这样,从express.js应用程序运行时打印的process.env包含那些环境变量,因为您将在部署node server.jsnode .bin/wwwnode server.js身份执行代码,而不是使用react-scripts start来执行代码。 js应用程序。 In this case, it is create-react-app who has the responsibility in setting the environment variables. 在这种情况下,由create-react-app负责设置环境变量。 Alternatively, you can manually set these environment variables in accordance to the create-react-app specifications. 或者,您可以根据create-react-app规范手动设置这些环境变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM