I have .env which has REACT_APP_API_URL = http://localhost:5000/. I use it in this code snippet
import axios from "axios";
const host = axios.create({
baseURL: process.env.REACT_APP_API_URL
});
const authHost = axios.create({
baseURL: process.env.REACT_APP_API_URL
});
When I try to output console.log(process.env.REACT_APP_API_URL); then the value is displayed undefined, why is that? The .env file is located in the directory where all client files are
CodePudding user response:
first install dotenv: npm i dotenv
after that import this to file: const dotenv = require("dotenv")
and config dot env: dotenv.config()
CodePudding user response:
Please check your .gitignore
file, sometimes the create-react-app
adds .env
file to the .gitignore entry. Maybe that's the reason.
CodePudding user response:
Do you try with dotenv package ?