motdotla / dotenv

Loads environment variables from .env for nodejs projects.
https://www.dotenvx.com
BSD 2-Clause "Simplified" License
19.18k stars 859 forks source link

Can we throw or stop execution through .env? #777

Closed chaitanya71998 closed 11 months ago

chaitanya71998 commented 1 year ago

Hi I was having a use case to use CODEBUILD_BUILD_NUMBER and assign it to one of the environment variable in .env file of react.

I want to stop execution from .env file making it as global source and throw error if there is no CODEBUILD_BUILD_NUMBER value as this is only place where every time different accesses of build/executions happens.

motdotla commented 1 year ago

Isn't CODEBUILD_BUILD_NUMBER injected at runtime by AWS?

motdotla commented 12 months ago

you can always halt in your code if you do something just like this after dotenv:

if (!process.env.CODE_BUILD_NUMBER) {
  // throw error here/halt
}
chaitanya71998 commented 11 months ago

you can always halt in your code if you do something just like this after dotenv:

if (!process.env.CODE_BUILD_NUMBER) {
  // throw error here/halt
}

this works!