# Vercel - Environment Variables and CLI (vercel env)
## Get Started
> Vercel is an end-to-end platform for developers, that allows you to create and deploy your web application. Vercel provides the following features to enable you to serve fast and personalized content to your users:
> - Deployments
> - CI/CD
> - Custom domains
> - Monitoring your project
## CLI
### vercel env
> The vercel env command is used to manage Environment Variables of a Project, providing functionality to list, add, remove, and export.
>
> `vercel env ls [environment]` : Using the vercel env command to list Environment Variables for a specific Environment in a Vercel Project.
### Example usage of getting environment variables of project
#### Download and install vercel CLI
Run commands:
```
npm i -g vercel
npm i -g vercel@latest
vercel --version
```
#### Link to the target project
Login to vercel
![](https://hackmd.io/_uploads/rJKEKDUni.png)
Setup scope and link to the existing project. When seeing **Error: EPERM: operation not permitted, mkdir 'C:\WINDOWS\System32\.vercel'**:
![](https://hackmd.io/_uploads/HJowqDUni.png)
**Solution:**
This error occurs because the current working directory of the PC is not in the project. Make sure you clone the project from github locally and `cd` to the project before running the command `vercel`.
Successfully set up:
![](https://hackmd.io/_uploads/rkgxaPUhs.png)
#### List all current environment variables
Run commands `vercel env ls [environment]`, for example, to list all **preview** environments:
```
vercel env ls preview
```
#### Get vercel environment variable for a certain branch
Source
https://github.com/vercel/vercel/pull/9028
https://github.com/vercel/vercel/releases/tag/vercel%4028.9.0
Update the vercel version to the version (or higher) that supports the feature
```
npm i -g vercel@28.9.0
```
Pull all environment variables of **preview** environment on **main** branch, vercel will create a file **.vercel/.env.preview.local** and store these variables into the file automatically
```
vc pull --branch main --environment preview
```
#### Access vercel features of an account without login
- Use **access token** that is set on the vercel account. Create a token with a proper **access scope** and **expired date**, and save the token.
![](https://hackmd.io/_uploads/Byyz1tqni.png)
- Open a terminal that has vercel installed, no need to log in vercel (to make sure the token works, should logout vercel if the current status is login)
- Add `--token [the vercel access token]` behind the command to give the right permission for the vercel command, for example:
```
vc pull --git-branch main --environment preview --token L2UKvAes45DDTBLBtdZJtbPM
```
- Will be able to access the vercel account successfully and see the command execution results
![](https://hackmd.io/_uploads/HknExt5ns.png)
#### Specify scope
When the current account is a member of a team on vercel, might need to provide the right scope to access the certain resource:
```
vc --scope myTeam pull --git-branch main --environment preview --token L2UKvAes45DDTBLBtdZJtbPM --yes
```
###### tags: `devops` `cicd` `vercel`