Before going live to production, setting the correct environment variables for your production environment is crucial.
As we've already seen before, you can organize your environment variables into three files:
.env: here, you can add variables that are shared across environments
.env.local: here go the variables that should be limited to your own machine, and it's recommended not to check this file in your VCS
.env.development: here, you can add the variables that should only be used during development
.env.production: here, you add the variables that should be used in your production environment
Typically, you would never place private data in your
.env.production file because that would cause your data to be leaked.
You should set any value that is not secret or confidential (such as your Firebase project's API Key or the feature flag's value) in the
Alternatively, suppose you are using variables such as the project's private key or any value that is supposed to be secret: in that case, you should ensure to inject these values from a secure environment, for example, your CI or your Vercel console.
As mentioned above, we can add variables shared across environments in the
.env configuration file. For example, MakerKit's
.env template looks like the below:
To use data only limited to your machine, use a
.env.local configuration file. Do not check this file in your VCS: therefore, you can use it to set private variables:
.env.development configuration, we will set variables such as the Firebase Emulator's configuration that will only run when running
next dev, e.g., when we're developing the application:
We will set variables for the production application in our
Rename the file
.env.production and add the required variables after creating your Firebase and Vercel projects:
This needs to be filled in before you push your application to your CI:
## SECRET KEYS ARE BEST ADDED TO YOUR CI
Careful! Do not add sensitive data here. Instead, add it from your CI or Vercel Console.