App Engine Environment Variables for Local Developer

What is the best way to set environment variables when developing nodejs on a local machine for an App Engine Flex environment? If they are installed in app.yaml, then they are not installed during local development. Is there a way to force this, or should I use something like dotenv and keep track of the same environment variables in two places?

+6
source share
3 answers

Sensitive data (such as API keys) should not be bound to the source code.

The way I got around this is to store the .env file in Google Storage. Then you can use @google-cloud/storage to load during production (using prestart hook) and dotenv to load variables into memory.

Here you can find the complete guide: http://gunargessner.com/gcloud-env-vars/


PS: I would go for Aidan's answer to store any data that is not sensitive. I myself have used dotenv satisfactorily in the past. Similarly, nconf , a package that gcloud itself uses examples . Pretty neat!

+2
source

Option 1:

require('dotenv').config({path: '/custom/project/root/app.yaml'})

Option 2:

Support both the .env file and the .yaml file with the same keys but different values ​​(local and GAE, respectively). In app.yaml, I remember to deploy my .env file by adding the following line:

skip_files : .env

Then you need to add a check ("dotenv"). config () to ensure that it is not an error or does not overwrite process variables if the .env file is not found.

0
source

Aidan's suggestion is good.

Since the configurations should be different in GAE and local, I would suggest option 2 is better - a separate .ENV for local and .YAML for GAE environments.

One small point though. I would suggest adding .gcloudignore files, something like below:

 .gcloudignore .git .gitignore .env staging.yaml node_modules/ 
0
source

Source: https://habr.com/ru/post/1263506/


All Articles