Import environment variables using the Postman VS Code extension
You can import .env files with environment variables from your API project into new environments in Postman. Then you can sync changes from your .env files to their respective environments in Postman. This enables you to maintain your environment variables in your API project and sync them with your environments in Postman when you’re ready to test your APIs.
Import environment variables
When you open your API project in VS Code, you’ll be notified by an in-app notification if the Postman VS Code extension detects new .env files. You can bulk import multiple .env files and their environment variables into Postman. You can also import a single .env file with its environment variables by clicking the link at the top of the file or right-clicking the file.
From the imported files in your API project, you can then open the environment variables in their respective environments in Postman.
Before importing your files, make sure your project has at least one file with the .env extension that stores your project’s environment variables in key-value pairs.
Import multiple .env files
To bulk import multiple .env files, do the following:
-
Open your API project in VS Code. The Postman VS Code extension checks your API project for
.envfiles you haven’t imported into Postman. -
In the in-app notification, click Import Now. You can also click
Import at the top of the sidebar, then select .env files to check for files. -
In the Import Environments tab, review the detected
.envfiles. You can enter text in the Search by name box to filter the list of files by name. -
(Optional) Click Edit next to a
.envfile you want to edit before importing into Postman. You can take the following actions:- Review the variables that import into Postman.
- Enter text in the Filter variables box to filter the list of variables by name or value.
- Click the environment name and rename it.
- Clear the checkbox next to variables you want to make unavailable. You can select each checkbox after import to make them available again.
- Change the variable type.
- Persist one or all current values (local) to their initial values (shared), syncing them with the Postman cloud after import. To persist all values, click
in the top right of the environment, then select Persist all. To persist a value, hover over a variable, click
, then select Persist.
- Reset one or all current values (local) to reflect their initial values (shared). To reset all values, click
in the top right of the environment, then select Reset all. To reset a value, hover over a variable, click
, then select Reset.
- Hover over a variable you don’t want to import, then click
.
- Click Reset to revert all of your changes.
- When you’re finished editing, click Done.
-
Select the checkbox next to one or more
.envfiles you want to import into new environments in Postman. Each.envfile is imported into its own environment in Postman. -
Click Import.
As you make changes to your imported .env files in your project, you can sync your changes with Postman.
Import a single .env file
To import a single .env file, do the following:
-
Open your API project in VS Code.
-
Open the
.envfile you want to import, then click Import to Postman at the top of the file. You can also right-click the.envfile, then click Import / Open in Postman.You won’t have the option to edit the environment variables before importing the
.envfile into Postman. You can edit the variables once they’re imported, such as changing the variable type. -
A new Postman environment opens in a new tab with the variables imported from your project. Review the imported variables.
-
Click Save if you make any changes to the environment.
As you make changes to your imported .env files in your project, you can sync your changes with Postman.
Work with imported .env files
Once your .env files are imported into Postman, you can open an imported file in your API project and click Open in Postman at the top. You can also right-click an imported file and select Import / Open in Postman. This opens the environment in a new tab with the environment variables you imported earlier.
When the environment is moved to a new workspace in Postman, these options open the relocated environment if you have permission to access it.
Learn more about managing environments in the Postman VS Code extension.
Sync environment variables
You can sync changes made to your imported .env files with their respective environments in Postman.
When you sync changes to imported .env files, both the current (local) and initial (shared) values are updated in their respective environments in Postman. The initial value is synced to the Postman cloud, sharing it with your team when you share the environment.
To detect and sync changes in .env files, do the following:
-
Open your API project in VS Code.
-
Edit
.envfiles you’ve already imported into Postman. -
Choose how you want to sync your changes:
- Open the file in your project or its respective environment in Postman. Then click Sync Now in the in-app notification.
- Open the file in your project and click Sync to Postman at the top of the file.
- Right-click the file and select Sync to Postman.
-
Repeat these steps for each imported
.envfile you’ve made changes to.