Skip to content

How to use environment variable in react-static? #1465

Discussion options

You must be logged in to vote

Yay, finally I found the answer.
I need to use dotenv package to achieve it.
Here is my steps:

  1. Install dotenv package:
npm i --save-dev dotenv
  1. Add .env file
GTAG_ID=UA-123124121-1
  1. Load environment variables in static.config.js
require('dotenv').config()
console.log('ENVIRONMENT: ', process.env.GTAG_ID);

Done, now I can access to environment variables in static.config.js 😉

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@sometimescasey
Comment options

@pappasG
Comment options

Answer selected by paulnguyen-mn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants