I built a project using React at the front and Strapi (based on Node.js) at the back.
On the client side, I'm trying to access my api url like so:
const apiUrl = process.env.API_URL || 'http://localhost:1337'
const strapi = new Strapi(apiUrl);
But process.env.API_URL is undefined. If I log process.env all I get is an object containing:
NODE_ENV: "development"
PUBLIC_URL: ""
How can I access my api_url ? I'm guessing there is a file where I should define API_URL myself?
Assuming you are using create react app, Make sure you add the prefix REACT_APP like REACT_APP_API_URL
. In your project src create a file .env.development
or .env.production
and add the your value with a key with the prefix
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With