This is a companion post to my AoG Client Library Basics course. (Launch discount included in that link is valid until end of day July 23rd 2019 Pacific Time).
In the course, I show you how to build a Google Assistant app which can fetch images from three different NASA APIs.
You need to apply for an API key to use the NASA APIs, but the key is supposed to be private and shouldn't be exposed to the public.
I use RunKit for sharing the code in that course. How can we make sure we use such a key in Runkit, where all the code is public by default (and cannot be made private)?
We use the idea of environment variables to be able to do this.
Environment variables are key value strings which are associated with an individual Runkit account. That is, only the Runkit account owner can see these environment variables.
To access your Environment variables, hover over the Runkit icon on the top left of your account and then click on the Environment settings link.
Now click on the Environment link.
You will now be able to see all your environment variables.
Create new environment variable
Suppose you wish to create a new environment variable.
You should just add the "key" (the name of the variable - e.g. NASA_API_KEY) into the left textbox and the "value" (whatever the actual API key is) into the right textbox. There is no explicit Save button - RunKit will just automatically save the value.
Using the environment variable
In your RunKit code, you can use these environment variables using the following syntax: