如何使用Node.js访问Google App Engine上的process.env [英] How to access process.env on Google App Engine with Nodejs

查看:57
本文介绍了如何使用Node.js访问Google App Engine上的process.env的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Google App引擎上使用React.

I'm using react on google app engine.

正如文档中所写: 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.

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

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.

怎么了?

推荐答案

以下环境变量由运行时设置"的含义适用于由 node 执行的应用程序.因此,从express.js应用程序运行时打印的 process.env 包含那些环境变量,因为您将以 node .bin/www node server.js 与 react-scripts启动相反.在这种情况下,由create-react-app负责设置环境变量.或者,您可以根据以下条件手动设置这些环境变量: create-react-app 规范.

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.

这篇关于如何使用Node.js访问Google App Engine上的process.env的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆