[英]How to access files from /tmp folder in google cloud?
I followed the guide here: http://gunargessner.com/gcloud-env-vars/ 我在这里遵循了指南: http : //gunargessner.com/gcloud-env-vars/
After reading the comment http://gunargessner.com/gcloud-env-vars/#comment-4061927247 , I also placed the .env
file in /tmp
. 在阅读评论http://gunargessner.com/gcloud-env-vars/#comment-4061927247之后 ,我还将.env
文件放置在/tmp
。
I would like to know how to set the contents of file /tmp/.env
to environment so that my app can access it from process.env.<varname>
我想知道如何将文件/tmp/.env
的内容设置为环境,以便我的应用程序可以从process.env.<varname>
访问它process.env.<varname>
const { Storage } = require('@google-cloud/storage')
const storage = new Storage()
const bucketName = 'env-var'
await storage
.bucket(bucketName)
.file('.env')
.download({ destination: '/tmp/.env' })
.then(() => {
console.log('env downloaded')
afterEnvProcess()
})
How do I now set the .env
file to dotenv
? 现在如何将.env
文件设置为dotenv
?
Well it depends on your app language but you can search for a dotenv
lib on github. 好吧,这取决于您的应用程序语言,但是您可以在github上搜索dotenv
库。
For example: 例如:
So when the app is started, you retrieve the .env
file from the fileStorage service (ie Google Cloud Storage) to /tmp
(for AppEngine case). 因此,在启动应用程序时,您将从fileStorage服务(即Google Cloud Storage)中的.env
文件检索到/tmp
(对于AppEngine而言)。 Then you can use the dotenv
lib to parse the .env
file en set the env vars. 然后,您可以使用dotenv
库来解析.env
文件,并设置env变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.