跳到主要内容

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.

Additionally, specific configurations for different environments can be created.

Strapi's environment variables

Strapi provides the following environment variables:

SettingDescriptionTypeDefault value
STRAPI_TELEMETRY_DISABLEDDon't send telemetry usage data to StrapiBooleanfalse
STRAPI_LICENSEThe license key to activate the Enterprise EditionStringundefined
NODE_ENVType of environment where the application is running.

production enables specific behaviors (see Node.js documentation for details)
String'development'
BROWSEROpen the admin panel in the browser after startupBooleantrue
ENV_PATHPath to the file that contains your environment variablesString'./.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_SOURCEMAPSForces the bundler to emit source-maps, which is helpful for debugging errors in the admin app.booleanfalse
FAST_REFRESH(Only applies to webpack)
Use react-refresh to enable "Fast Refresh" for near-instant feedback while developing the Strapi admin panel.
booleantrue
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).

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:

./config/server.js

module.exports = {
host: '127.0.0.1',
};
./config/env/production/server.js

module.exports = ({ 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