Rounak Jain
Rounak Jain

Reputation: 499

How to access files from /tmp folder in google cloud?

I followed the guide here: 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.

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>

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?

Upvotes: 1

Views: 2744

Answers (1)

rmasclef
rmasclef

Reputation: 108

Well it depends on your app language but you can search for a dotenv lib on github.

For example:

So when the app is started, you retrieve the .env file from the fileStorage service (i.e Google Cloud Storage) to /tmp (for AppEngine case). Then you can use the dotenv lib to parse the .env file en set the env vars.

Upvotes: 1

Related Questions