In my application I have created an environment variables into .env.local file and fetching it through process.env.ENV_KEY into component. But it is not returnig the actual value and instead it returns undefined value.
.env.local
API_ENDPOINT = "http://localhost:4200/api/"
In component I am getting the value as process.env.API_ENDPOINT but it returns as undefined
App.js
function App(props) {
const loginUser = async event => {
event.preventDefault()
axios.post(`${process.env.API_ENDPOINT}/login`, data)
.then((response) => {
router.push('/')
})
}
}
I have also tried to config into env.js file but that also not worked any how.
exports.env = {
API_ENDPOINT: process.env.API_ENDPOINT
}
And into component have imported as
import {env} from './config.js'
function App(props) {
const loginUser = async event => {
event.preventDefault()
axios.post(`${env.API_ENDPOINT}/login`, data)
.then((response) => {
router.push('/')
})
}
}
Moreover, I have also tried to create a build and then run the project but then also it returns undefined value.
Reference that I checked