Documents
access-configuration-values
access-configuration-values
Type
External
Status
Published
Created
Mar 5, 2026
Updated
Mar 5, 2026

How to access to configuration values from the code#

All the configuration files are loaded on startup and can be accessed through the strapi.config configuration provider.

If the /config/server.ts|js file has the following configuration:

module.exports = {
  host: '0.0.0.0',
};
export default {
  host: '0.0.0.0',
};

then the server.host key can be accessed as:

strapi.config.get('server.host', 'defaultValueIfUndefined');

Nested keys are accessible with the .

Configuration files can either be .js, .ts, or .json files.

When using a .js or .ts file, the configuration can be exported:

  • either as an object:

    module.exports = {
      mySecret: 'someValue',
    };
    
    export default {
      mySecret: 'someValue',
    };
    
  • or as a function returning a configuration object (recommended usage). The function will get access to the env utility:

    module.exports = ({ env }) => {
      return {
        mySecret: env('MY_SECRET_KEY', 'defaultSecretValue'),
      };
    };
    
    export default ({ env }) => {
      return {
        mySecret: env('MY_SECRET_KEY', 'defaultSecretValue'),
      };
    };