Using Environment variables important to keep your private information secure. Next.js comes with built-in support for environment variables.
superplate has a plugin to generate those files for different environments automatically.
Next.js has built-in support for loading environment variables from
process.env.DB_PASS into the Node.js environment automatically.
Next.js allows us to set defaults in
.env (all environments),
.env.development (development environment) and .
env.production (production environment).
In order to expose a variable to the browser you have to prefix the variable with
In the same way you can set defaults for development or production environments, you can do the same with
.env.test file for testing environment
.env.test is useful when running tests with tools like jest or cypress where you need to set specific environment variables only for testing.