So I have an API_KEY which I'm storing in .env file, and using javascript template I had no problems accessing .env file. But now I'm using a typescript template and I want to know how can I use variables from .env file.
It looks like this:
API_KEY={myapikey}
API_BASE={api_base}
And that's the way I access it in a redux slice:
const API_BASE = process.env.API_BASE;
const TMDB_API_KEY = process.env.API_KEY;
And then I fetch data using redux thunk:
export const fetchPopular = createAsyncThunk('popular/fetchPopular', async () => {
const response = await axios.get<MovieResults>(`${API_BASE}movie/popular?api_key=${TMDB_API_KEY}`);
console.log(response.data);
return response.data.results;
})
But in the end it returns me undefined, although when I declared api key and api base directly everything was alright.
Edit:
I had dot-env installed and now I imported it in my index.tsx using:
require('dotenv').config()
console.log(process.env)

dotenvinstalled, or a package that depends on it (likereact-dotenv)? npmjs.com/package/dotenv