> For the complete documentation index, see [llms.txt](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/core-module-backend-development-with-nestjs/configuration/environment-variables.md).

# Environment variables

Variables that are isolated from the codebase.

We'll begin with our database credentials. First, create, at the root of the project, the file <mark style="color:purple;">.env</mark>, which will hold our environment variables. Here, we can safely store the credentials.

```properties
DATABASE_USER = postgres
DATABASE_PASSWORD = pass123
DATABASE_HOST = localhost
DATABASE_PORT = 5432
DATABASE_NAME = postgres
```

{% hint style="info" %}
This file will never be published to the code repository, as the file <mark style="color:purple;">.gitignore</mark> includes it. You may notice that the file name in the file explorer is grayed out.
{% endhint %}

Even though we have all those credentials, we can use just the **URL** to connect to the database, which can be created from them. For this reason, once again in <mark style="color:purple;">.env</mark>, let's create the URL.

```properties
DATABASE_URL = postgresql://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
```

As we have just created the <mark style="color:purple;">.env</mark> file, we can already create the <mark style="color:purple;">.env.example</mark> file too. It is a reflection of the <mark style="color:purple;">.env</mark> but with sample data, so that other developers may know the structure they must have in their own <mark style="color:purple;">.env</mark> file. As our <mark style="color:purple;">.env</mark> file has data for development testing, we can just copy its contents over to <mark style="color:purple;">.env.example</mark>. Other developers may then copy this to their <mark style="color:purple;">.env</mark> and adjust as necessary.

However, before we can begin using these variables, some issues need to be resolved, and that will be done in the next section.
