node.js - 如何使用 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
. 因此,process.env
从 express.js 应用程序运行时打印的内容包含这些环境变量,因为您将执行代码,node .bin/www
而node server.js
不是react-scripts start
在部署 react.js 应用程序时。在这种情况下,由 create-react-app 负责设置环境变量。或者,您可以根据规范手动设置这些环境变量。create-react-app
推荐阅读
- jspdf - 用jspdf打印€符号的问题
- html - 我的文本在顶部和底部都有边距。为什么?
- arrays - 用除数替换 mod 函数中的 0
- python - 名称空间被覆盖的模块中的monkeypatch函数
- python - 如何按内部列表中的第一个值对列表列表进行排序
- javascript - JavaScript loop through two arrays
- python - 如何从大数据文件中找到两个选定列的总和?
- powershell - 使用 Cim 和 Powershell 删除过去 6 个月内未登录的所有用户配置文件
- android - android数据绑定开关监听器不起作用
- rest - 保护对 Vault Secrets 管理的 REST 调用