How to switch between .env file locally?
Unanswered
ashuvssut (ashu) posted this in #help-forum
I have 2 env files present locally:-
I would like to occassionally switch between them
I use yarn workspaces. When I run
.env, .env.demo"I would like to occassionally switch between them
.env, .env.demo to test my app on different configurations// From package.json
"scripts": {
"dev": "next dev", // This uses .env file. Not issues with this one.
"dev:demo": "env-cmd -f .env.demo yarn next dev", // THIS IS NOT WORKING:- .env.demo is not getting loaded but .env gets loading instead
"build": "next build",
"start": "next start",
"lint": "next lint"
},I use yarn workspaces. When I run
yarn dev:demo, the .env.demo is not getting loaded but .env gets loading instead. Check screeshot:-2 Replies
the files loaded by next can only be controlled by the NODE_ENV env variable, that can only be one of
so even if you load other env files next will load it's own file based on NODE_ENV eg .env.production .env.development etc or .env if non more specific is used and show that in the logs
I tried your code and it works
using envs in both .env and .env.demo, where .env.demo overrides the ones used in both
production, development (default) or testso even if you load other env files next will load it's own file based on NODE_ENV eg .env.production .env.development etc or .env if non more specific is used and show that in the logs
I tried your code and it works
using envs in both .env and .env.demo, where .env.demo overrides the ones used in both