custom-env icon indicating copy to clipboard operation
custom-env copied to clipboard

Example on Loading from the current environment

Open abdullahIsa opened this issue 3 years ago • 2 comments
trafficstars

Hello thanks for this but I am a bit confused on how to make the env automatically change if in production or development, i don't want to always be changing the value.

How to do so ? require("custom-env").env("development"); // change based on current environment as cant do an if check since its at the top of file.

Thanks.

abdullahIsa avatar Dec 12 '21 16:12 abdullahIsa

Using a environment file name .env.development

  1. Firstly set your require to below - Removing development and adding true (boolean). require("custom-env").env(true);

  2. Set NODE_ENV to development. e.g. set NODE_ENV=development in your package.json

jeremydein avatar Feb 11 '22 04:02 jeremydein

Using a environment file name .env.development

  1. Firstly set your require to below - Removing development and adding true (boolean). require("custom-env").env(true);
  2. Set NODE_ENV to development. e.g. set NODE_ENV=development in your package.json

Hello, thanks, I did tried that, i am on windows and using this in node.js, i use nodemon so i always starts by using npm run server .

package.json

image

env files

image

index.js

image

Error

image

abdullahIsa avatar Feb 11 '22 10:02 abdullahIsa

Update: ended up using cross-env with dotenv-flow i think my mistake was i was i was adding && after NODE_ENV=production

abdullahIsa avatar Sep 19 '22 11:09 abdullahIsa