Multi-Environments
There are 2 important environment variables to understand while working with NextJS application.
NODE_ENV
This variable determines the NextJS application environment. The allowed values for NODE_ENV are:
- production
- development
- test
While working locally using
next dev, NODE_ENV is set todevelopment. It enables debug logs. While application is build usingnext buildcommand, NODE_ENV is set toproduction. It disables to debug logs. Learn more on Next JS docs: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order
APP_ENV
This variables determines the deifferent environments configured on AWS environment. Possible values are:
dev: Corresponds to development environment and GitHub CICD branch ismainstaging: Corresponds to staging environment and GitHub CICD branch isstagingprod: Corresponds to production environment and GitHub CICD branch isproduction
Loading APP_ENV variables
.envfile contains the common variables between 3 environments.environments/.env.*files contains theAPP_ENVspecific variables.loadEnv.shscript is used before NextJS commands to load the correctAPP_ENVspecific variables into.env.localfile. Checkout package.json scripts for more reference.
By default, APP_ENV is set to dev is not specified. However it can be set manually to different env before running npm command
> APP_ENV=staging npm run dev
Last updated on