PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 19, 2022

[FIXED] How to use environment variables in React?

 August 19, 2022     environment-variables, reactjs     No comments   

Issue

process.env.VARIABLE_NAME

This does not work for some reason. It works in node after configuration the dotenv library.

What do I need to do in the react side to make it work?


Solution

You can use dotenv in React only for variables that start with REACT_APP_.

So,

// index.js
require('dotenv').config();
console.log(process.env.REACT_APP_API_KEY) //works
console.log(process.env.DB_USER) //does not work


Answered By - cSharp
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing