Add Environment Variables to Your Vercel Project



What are Environment Variables?

Environment variables are essential for managing sensitive information, such as API keys or database credentials, in a secure and maintainable way.

Environment variables are key-value pairs used to configure applications without hardcoding sensitive or environment-specific information into the codebase. They are especially useful for:

  • Storing Sensitive Information: Protect API keys, tokens, and passwords from being exposed in the code.
  • Environment-Specific Configuration: Configure values that vary between development, staging, and production environments.
  • Improved Security: Keep sensitive data out of version control systems like Git.

Why Use Environment Variables in Vercel?

Vercel provides a simple and secure way to manage environment variables. It supports environment variables for different stages:
  • Development: For local development and testing.
  • Preview: For pull request builds and deployment previews.
  • Production: For live deployments on your production domain.
By using environment variables, you can ensure your application behaves correctly in all stages without exposing sensitive data.

Adding Environment Variables to a Vercel Project

Let's understand step-by-step how one can add environment variables to a Vercel project -

Step-1: Login to Vercel app from here https://vercel.com

Select the project where you want to add the environment variables.


Step-2: Navigate to Project Settings


Step-3: Open the Environment Variables section.


Scroll down to the Environment section within the settings.


Step-4: Add Environment Variables

Key: Enter the name of your variable (e.g., NEXT_PUBLIC_API_KEY).
Value: Enter the corresponding value for the variable (e.g., your-api-key-here).


Environment:
Choose the environment where this variable should be available:

Development: For local development using vercel dev.

Preview: For deployment previews (pull request builds).
Production: For the live production environment.
Click save to add the environment variables.

Step 5: Deploy or Redeploy Your Project

After adding the environment variables, redeploy your project to make the variables available in your application.
1. Go to the Deployments tab in the Vercel dashboard in the project.


Click on latest deployment and choose "Redeploy" button to apply environment variables.


By following the above procedure, you can securely add and manage environment variables in Vercel. It will ensure that your application functions seamlessly across different environments while protecting sensitive information.

Geethanjali Gandu
Geethanjali Gandu

Tech Enthusiast

Updated on: 2024-12-09T12:10:49+05:30

114 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements