0

I'm creating an SSR React app, I'm using babel-node for server and webpack for client. I'm facing sharing/accessing env variables. For client (webpack), I use webpack.DefinePlugin and access .env with fetch(${API_V1}/get-product), Without process.env`

But not able to do the same on babel-node. I don't want to update all the files with process.env.API_V1 and just want to access envs like API_V1.

Is there any plugin or method to achieve this?

Thanks in advance.

More Info

ReferenceError: WEB_URL is not defined
Raman Choudhary
  • 4,283
  • 2
  • 14
  • 25
  • Do you mean trying to read the env file as running on node env (server side)? – tmhao2005 Nov 30 '20 at 13:52
  • @tmhao2005 thanks for quick reply. On client side i use webpack's definePlugin. and on server dotenv. But the syntax is different to access envs on both platforms. I want to keep the client side syntax, i.e direct using the var name 'WEB_URL' for example. Not able to achieve it on server. Please help! – Raman Choudhary Nov 30 '20 at 13:56
  • Ah I see. Why don’t you set that value as global such as global.URL = something at the entry point of your server side? – tmhao2005 Nov 30 '20 at 14:00

0 Answers0