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

余生颓废 提交于 2021-01-28 08:48:49

问题


I'm using react on google app engine.

As is written in the documentation: 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:

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?


回答1:


What it means by "The following environment variables are set by the runtime" is applicable to applications executed by 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. In this case, it is create-react-app who has the responsibility in setting the environment variables. Alternatively, you can manually set these environment variables in accordance to the create-react-app specifications.



来源:https://stackoverflow.com/questions/57729098/how-to-access-process-env-on-google-app-engine-with-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!