Environment configuration and variables
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.
An env()
utility can be used to retrieve the value of environment variables and cast variables to different types.
Additionally, specific configurations for different environments can be created.
Strapi's environment variables
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 Node.js documentation 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) plugin 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 react-refresh to enable "Fast Refresh" for near-instant feedback while developing the Strapi admin panel. | boolean | true |
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
).
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:
- JavaScript
- TypeScript
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