1. 13
    Extract Environment Variable for the API Key
    32s

Extract Environment Variable for the API Key

Colby Fayock
InstructorColby Fayock
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 4 years ago

While our API key is exposed when our page loads the map, we can configure our API keys to have 1 for development that no one can ever see and one for production where we would restrict the URL to our app.

To do this, we can use Create React Apps's built-in environment variable solution. You should be able to find an .env.shared.sample file that you can duplicate and remove sample from the name. You can then use this to fill in your details for the variables.

Click here for exercise instructions

Colby Fayock: [0:00] Before we start using our API key, we want to figure out a way to use it as an environment variable. At the top of the lessons folder, we have a file called env.shared.sample.

[0:08] The first thing we're going to do is move that file to the same name, except we're going to remove the sample. If we open that file, we can see it has a few things. It has a Mapbox API key, a Mapbox user ID and a Mapbox style ID.

[0:20] Our lessons are set up to already use those environment variables so that our API key, user ID, and style ID can carry on through all the lessons. For our first variable, we're going to copy our API key and paste it in our environment file, and we'll be ready to go.

egghead
egghead
~ 10 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today