%%
date:: [[2022-12-25]]
%%
# [[Using environment variables in js]]
It's a good practice to use [[Environment variables]] instead of hardcoding potentially confidential values into your code. In [[JavaScript]], the easiest way to do this is to use the [[dotenv library]].
## Using `dotenv` in JavaScript
### Installation
When using [[NodeJS]], install it this way:
```bash
npm install dotenv
```
### Importing the library
Add the following line to the top of your JavaScript code to make sure that your app includes the right library:
```js
require('dotenv').config();
```
### Setting the values of the environment variables
Create a new text file called `.env`. This is where you should put all the variables and their actual values, like this:
```plain
ACCESS_TOKEN=tokenhere
CLIENT_SECRET=secrethere
CLIENT_KEY=keyhere
READWISE_TOKEN=tokenhere
DOMAIN=domain.name
```
> [!warning] Add `.env` to your `.gitignore`!
> If you're pushing the code to a remote repository, make sure you [[Ignoring files in Git|ignore this file]]. Instead of sharing `.env`, copy the contents (sans values) to a new file named `.env-sample` instead, and then push *that* file to the remote. That will still help people understand what they need to set.