0

Have an environment variable in my project as

process.env.GOOGLE_MAPS_API

which a google api key and use it to render map and have the below code which is not working:

export default GoogleApiWrapper({
  apiKey: (process.env.GOOGLE_MAPS_API)
})(MapContainer)

But when I use the api key directly it is rendering the map

export default GoogleApiWrapper({
      apiKey: ('AI************************')
 })(MapContainer)

How do I use the google api key as environment variable in the above code?

1 Answer 1

2

If you are using Webpack to bundle the code, there is DefinePlugin Sample code -

// webpack.config.js
    new webpack.DefinePlugin({
  GOOGLE_MAPS_API: JSON.stringify(process.env.GOOGLE_MAPS_API)
})

app.js

console.log(GOOGLE_MAPS_API); // logs API_KEY
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.