To create environment variables that should be used only in the development version of your Nextjs project, you can make a file called .env.development
at the root of the Nextjs project folder.
This file will be used (along with the .env
if you have it defined) to take environment variables in the development version or when using the next dev
command in the terminal.
For example, let's say you have an environment variable called SERVER_ID=12345
which you need to use only in the development version of your Next.js project, so we can define this environment variable in the .env.development
file like this,
.env.development file
SERVER_ID = 12345;
- Useful in decoupling information from
production
anddevelopment
versions - Check out How to create and use environment variables in Nextjs? to get a detailed explanation on creating and using environment variables in general in Nextjs.