Handle environments
Answered
Black Caiman posted this in #help-forum
Black CaimanOP
Hello. In short.. I want to have multiple environment in my project, following as:
1. .env -> local
2. .env.staging -> staging
3. .env.prod1 -> production app1
4. .env.prod2 -> production app2
Same repository used for two projects parallel, just some small modification (favicon, logo, etc.) are made based on an environment variable.
I saw some solutions with 3rd party packages. Is there a way to solve the problem without installing package?
.gitignore would have the local & production in it.
Due to I'm working by myself I do manual push to my registry (docker) for production releases, can anyone help me out with a package.json script which handles the correct environment for the specific build?
Thanks.
1. .env -> local
2. .env.staging -> staging
3. .env.prod1 -> production app1
4. .env.prod2 -> production app2
Same repository used for two projects parallel, just some small modification (favicon, logo, etc.) are made based on an environment variable.
I saw some solutions with 3rd party packages. Is there a way to solve the problem without installing package?
.gitignore would have the local & production in it.
Due to I'm working by myself I do manual push to my registry (docker) for production releases, can anyone help me out with a package.json script which handles the correct environment for the specific build?
Thanks.
Answered by @ts-ignore
"start:app1":"dotenv -e .env.prod1 -- next start"
"start:app2":"dotenv -e .env.prod2 -- next start"10 Replies
@Black Caiman Hello. In short.. I want to have multiple environment in my project, following as:
1. .env -> local
2. .env.staging -> staging
3. .env.prod1 -> production app1
4. .env.prod2 -> production app2
Same repository used for two projects parallel, just some small modification (favicon, logo, etc.) are made based on an environment variable.
I saw some solutions with 3rd party packages. Is there a way to solve the problem without installing package?
.gitignore would have the local & production in it.
Due to I'm working by myself I do manual push to my registry (docker) for production releases, can anyone help me out with a package.json script which handles the correct environment for the specific build?
Thanks.
Ik you asked without packages but idk if its possible but you can use
dotenv-cli and add scripts which log respective env files"start:app1":"dotenv -e .env.prod1 -- next start"
"start:app2":"dotenv -e .env.prod2 -- next start"Answer
and since the file names are not what nextjs looks for, it won't load them
Black CaimanOP
Thanks for the quick response.
Seems awesome
I'll create a folder to make it sure not loading the wrong env
If I'm correct, the docs says it's looking in the root folder for the .env extensions
yes
Black CaimanOP
Saved my life, I find only rarely updated packages, but this seems good.
Thanks