How to create environment variables only to be used in the development version of Nextjs?

February 25, 2021 - 1 min read

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;

Feel free to share if you found this useful 😃.