0
votes

I have two .env files (.env.development and .env.production) and two different build scripts, one for dev and one for prod. Now I want exactly one build script and depending on a global environment variable I want to decide what of this two .env files should be used for the build.

Is there a way to write in a build script a checker on what the environment variable is set ?

1
Which platform are you using for production? - onuriltan
What do you mean what platform ? - JScripter
I mean in production where do you serve the app, Heroku, AWS etc - onuriltan
On a normal unix server with apache. The problem is, that I have two build scripts and I want exactly one, but the NODE_ENV variable should decide what file should be used at the build - JScripter
May I ask what unix server, Ubuntu, CenOS or something else, I'm asking because there will be ways to set env variables to OS? - onuriltan

1 Answers

1
votes

So you can solve this problem by passing environmental variables from your unix server in production, but when in development pass it from .env file, this way you don't need to add twi build scripts because it will get variables from .env or from unix env.

To pass env variables to your Node.js app from Unix OS is like

Open Terminal and write the command as

> export MY_ENV=my environment value

After that you will see the env variable with

> echo "$MY_ENV"

But I suggest you to use Docker and set the env variables to your Docker env this way you will separate your env variables from OS env and prevent inconsistencies