DEV Community

Cover image for Export .env from Vercel: New Laptop, Old Project? No Problem!
Clara Situma
Clara Situma

Posted on

Export .env from Vercel: New Laptop, Old Project? No Problem!

Starting fresh on a new laptop or revisiting an old project doesn’t mean you’re stuck hunting for missing keys.

With Vercel, pulling down your environment variables is a breeze. Let’s dive in and get your project up and running in no time!

Exporting .env from Vercel

Here’s how you can seamlessly retrieve your .env file from Vercel:

Step 1: Install the Vercel CLI

Before you start, make sure the Vercel CLI is installed globally on your system. If not, install it via npm:

npm install -g vercel

Enter fullscreen mode Exit fullscreen mode

Step 2: Link Your Local Project

Navigate to the root directory of your project and run the following command:

vercel link

Enter fullscreen mode Exit fullscreen mode

Follow the prompts to select your account (personal or team) and link to the existing Vercel project.

If you’re linking to a specific project (e.g., buyrentzanzibarclient), the CLI will list it—simply select it.

Step 3: Pull the .env File

Once linked, pull down your environment variables directly into a local .env file:

vercel env pull

Enter fullscreen mode Exit fullscreen mode

This creates a .env file in your project’s root directory, pre-filled with all the environment variables set in the Vercel dashboard.

Step 4: Verify the .env File

Open the .env file to ensure everything is in place. It should look something like this:

API_URL=https://api.example.com
DATABASE_URL=your-database-url
SECRET_KEY=your-secret-key
Enter fullscreen mode Exit fullscreen mode

Pro Tip: Secure Your .env File
Once you’ve exported your .env file, add it to your .gitignore to prevent it from being pushed to your repository

Top comments (0)