# Environment variables configuration

> Source: https://docs.strapi.io/cms/configurations/environment

Strapi-specific environment variables and `.env usage` enable per-environment configs, with `env()` helpers for casting values.

Strapi provides specific environment variable names. Defining them in an environment file (e.g., `.env`) will make these variables and their values available in your code.

:::tip
An `env()` utility can be used to [retrieve the value of environment variables](/cms/configurations/guides/access-cast-environment-variables#accessing-environment-variables) and [cast variables to different types](/cms/configurations/guides/access-cast-environment-variables).
:::

Additionally, specific [configurations for different environments](#environment-configurations) can be created.

## Strapi's environment variables {#strapi}

Strapi provides the following environment variables:

 Setting                                                    | Description                                                                                                                                                                                                                                                                   | Type      | Default value   |
|------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|-----------------|
| `STRAPI_TELEMETRY_DISABLED`                                | Don't send telemetry usage data to Strapi                                                                                                                                                                                                                                     | `Boolean` | `false`         |
| `ADMIN_PATH` | Path the admin panel is served under. Defaults to the pathname of [`admin.url`](/cms/configurations/admin-panel#admin-panel-server) and is also injected into the admin JS bundle at build time so the front end knows where it is mounted. | `String` | `'/admin'` |
| `STRAPI_ADMIN_BACKEND_URL` | URL the admin panel uses to reach the back-end server. When the back end and the admin panel share the same origin, the value resolves to the pathname of [`server.url`](/cms/configurations/server) (typically `'/'`); otherwise it resolves to the full back-end URL. The value is injected into the admin JS bundle at build time, so override it before running `strapi build` if you need to pin a specific URL. | `String` | `auto-derived` |
| `STRAPI_LICENSE`                                           | The license key to activate the Enterprise Edition                                                                                                                                                                                                                            | `String`  | `undefined`     |
| `NODE_ENV` | Type of environment where the application is running.<br/><br/>`production` enables specific behaviors (see [Node.js documentation](https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production) for details) | `String` | `'development'` |
| `BROWSER`                                                  | Open the admin panel in the browser after startup                                                                                                                                                                                                                             | `Boolean` | `true`          |
| `ENV_PATH`                                                 | Path to the file that contains your environment variables                                                                                                                                                                                                                     | `String`  | `'./.env'`      |
| `STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE` <br/><br/>_Optional_ | Initialization locale for the application, if the [Internationalization (i18n) feature](/cms/features/internationalization) is installed and enabled on Content-Types (see [Configuration of i18n in production environments](/cms/features/internationalization#configuration)) | `String`  | `'en'`          |
| `STRAPI_ENFORCE_SOURCEMAPS`                                | Forces the bundler to emit source-maps, which is helpful for debugging errors in the admin app.  | `boolean` | `false`          |
| `FAST_REFRESH`                                             | _(Only applies to webpack)_<br/>Use [react-refresh](https://github.com/pmmmwh/react-refresh-webpack-plugin) to enable "Fast Refresh" for near-instant feedback while developing the Strapi admin panel.                                                                                                       | `boolean` | `true`          |
| `HOST` | Address the Strapi server listens on | `String` | `0.0.0.0` |
| `PORT` | Port used by the Strapi server | `Number` | `1337` |
| `APP_KEYS` | Comma-separated keys used to sign cookies and other secrets | `String` | `auto-generated` |
| `API_TOKEN_SALT` | Salt used when creating [API tokens](/cms/features/api-tokens) | `String` | `auto-generated` |
| `ADMIN_JWT_SECRET` | Secret for JWT tokens used in the admin panel. Required when [`admin.serveAdminPanel`](/cms/configurations/admin-panel#admin-panel-behavior) is `true` (the default); can be omitted for API-only deployments running with `serveAdminPanel: false`. | `String` | `auto-generated` |
| `JWT_SECRET` | Secret for JWT tokens generated by the [Users & Permissions](/cms/features/users-permissions) feature | `String` | `auto-generated` |
| `TRANSFER_TOKEN_SALT` | Salt used for transfer tokens by the [Data Management](/cms/features/data-management) feature | `String` | `auto-generated` |
| `DATABASE_CLIENT` | Database client to use (e.g., `sqlite`) | `String` | `sqlite` |
| `DATABASE_FILENAME` | Location of the SQLite database file | `String` | `.tmp/data.db` |

:::tip
Prefixing an environment variable name with `STRAPI_ADMIN_` exposes the variable to the admin front end (e.g., `STRAPI_ADMIN_MY_PLUGIN_VARIABLE` is accessible through `process.env.STRAPI_ADMIN_MY_PLUGIN_VARIABLE`).

This works when the admin panel is built from your project, for example in self-hosted deployments. Strapi Cloud does not expose `STRAPI_ADMIN_*` variables to the admin front end.
:::

### Example `.env` file

The Strapi CLI generates an `.env` and an `.env.example` file when creating a new project. The files contain automatically-generated security keys and database settings similar to the following:

```env title=".env.example"
HOST=0.0.0.0
PORT=1337
APP_KEYS="toBeModified1,toBeModified2"
API_TOKEN_SALT=tobemodified
ADMIN_JWT_SECRET=tobemodified
TRANSFER_TOKEN_SALT=tobemodified
JWT_SECRET=tobemodified
ENCRYPTION_KEY=tobemodified
```
The variables might differ depending on options selected on project creation.

```env title=".env"
# Server
HOST=0.0.0.0
PORT=1337

# Secrets
APP_KEYS=appkeyvalue1,appkeyvalue2,appkeyvalue3,appkeyvalue4
API_TOKEN_SALT=anapitokensalt
ADMIN_JWT_SECRET=youradminjwtsecret
TRANSFER_TOKEN_SALT=transfertokensaltvalue
ENCRYPTION_KEY=yourencryptionkey

# Database
DATABASE_CLIENT=sqlite
DATABASE_HOST=
DATABASE_PORT=
DATABASE_NAME=
DATABASE_USERNAME=
DATABASE_PASSWORD=
DATABASE_SSL=false
DATABASE_FILENAME=.tmp/data.db
```

Set these environment variables for secure authentication with [sessions management](/cms/features/users-permissions#jwt-management-modes) configuration:

```bash title=".env"
# Admin authentication
ADMIN_JWT_SECRET=your-admin-secret-key

# Cookie domain (optional)
ADMIN_COOKIE_DOMAIN=yourdomain.com

# Users & Permissions JWT secret
JWT_SECRET=your-content-api-secret-key

# Users & Permissions session management
UP_JWT_MANAGEMENT=refresh  # or 'legacy-support'
UP_SESSIONS_ACCESS_TTL=604800  # 1 week in seconds
UP_SESSIONS_MAX_REFRESH_TTL=2592000  # 30 days in seconds
UP_SESSIONS_IDLE_REFRESH_TTL=604800  # 7 days in seconds
UP_SESSIONS_HTTPONLY=false  # true for HTTP-only cookies
UP_SESSIONS_COOKIE_NAME=strapi_up_refresh
UP_SESSIONS_COOKIE_SAMESITE=lax
UP_SESSIONS_COOKIE_PATH=/
UP_SESSIONS_COOKIE_SECURE=false  # true in production
```

## Environment configurations

Configurations can be created with the following naming and structure conventions: `./config/env/{environment}/{filename}`. This is useful when you need specific static configurations for specific environments and using environment variables is not the best solution.

These configurations will be merged into the base configurations defined in the `./config` folder.
The environment is based on the `NODE_ENV` environment variable, which defaults to `development`.

When starting Strapi with `NODE_ENV=production` it will load the configuration from `./config/*` and `./config/env/production/*`. Everything defined in the production configuration will override the default configuration. In combination with environment variables this pattern becomes really powerful.

For instance, using the following configuration files will give you various options to start the server:

```js title="./config/server.js"

module.exports = {
  host: '127.0.0.1',
};
```

```js title="./config/env/production/server.js"

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
});
```

```ts title="./config/server.ts"

  host: '127.0.0.1',
});
```

```js title="./config/env/production/server.ts"

  host: env('HOST', '0.0.0.0'),
});
```

With these configuration files the server will start on various ports depending on the environment variables passed:

```bash
yarn start                                   # uses host 127.0.0.1
NODE_ENV=production yarn start               # uses host defined in .env. If not defined, uses 0.0.0.0
HOST=10.0.0.1 NODE_ENV=production yarn start # uses host 10.0.0.1
```

<br/>

To learn deeper about how to use environment variables in your code, please refer to the following guide:

- [Access and cast variables](/cms/configurations/guides/access-cast-environment-variables): Learn how to access and cast environment variables with the env() utility.
