import SampleEnv from '/docs/snippets/sample-env.md'
Environment configuration and variables#
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.
Additionally, specific configurations for different environments 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 |
STRAPI_LICENSE | The license key to activate the Enterprise Edition | String | undefined |
NODE_ENV | Type of environment where the application is running.production enables specific behaviors (see 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 Optional | Initialization locale for the application, if the Internationalization (i18n) feature is installed and enabled on Content-Types (see Configuration of i18n in production environments) | 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) Use 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 | String | auto-generated |
ADMIN_JWT_SECRET | Secret for JWT tokens used in the admin panel | String | auto-generated |
JWT_SECRET | Secret for JWT tokens generated by the Users & Permissions feature | String | auto-generated |
TRANSFER_TOKEN_SALT | Salt used for transfer tokens by the 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 |
Example .env file#
Set these environment variables for secure authentication with sessions management configuration:
# 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:
module.exports = {
host: '127.0.0.1',
};
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
});
export default ({ env }) => ({
host: '127.0.0.1',
});
export default ({ env }) => ({
host: env('HOST', '0.0.0.0'),
});
With these configuration files the server will start on various ports depending on the environment variables passed:
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
To learn deeper about how to use environment variables in your code, please refer to the following guide: