How to use Environment Variables in GCloud App Engine (Node.js)
UPDATE
Simon Schilling tells me this is not working anymore.
UPDATE
My team developed a package for this @invisible/deploy. But we’re off Google App Engine for now. Too many problems with it.
Don’t put your secret information in your code
App Engine allows one to define environment variables through app.yaml
. But you probably want to commit app.yaml
to your version control (e.g. git).
How to solve this dilemma?
Store secrets in Google Cloud Storage
Go to Google Cloud
-> Storage
-> Browser
.
Create a Bucket. The name should include:
- “envvars”
- your project name
- your domain (optional)
Let’s say I create a project named “blog”, to host my blog. I would name it envvars.blog.gunargessner.com
.
Bucket names are unique across Google Cloud (not just Company or Project wide). Names ending with a domain are reserved. But you have to go through the trouble of verifying ownership.
Upload to this bucket your .env
file. Example:
Importing Bucket content into process.env
Install dependencies
Add prestart
hook to package.json
Add script to download .env
Use dotenv
to load content into process.env
Making it work locally (development environment)
It works out of the box if you have a .env
file in your local environment.