Skip to main content
Version: 2.3

Configuration

Configuration is a value object holding the SDK configuration. We can use it in two ways:

  1. When using Apify class, we can get the instance configuration via sdk.config
const { Apify } = require('apify');

const sdk = new Apify({ token: '123' });
console.log(sdk.config.get('token')); // '123'
  1. To get the global configuration (singleton instance). It will respect the environment variables.
console.log(Configuration.getGlobalConfig().get('token')); // returns the token from APIFY_TOKEN env var

Supported Configuration Options

KeyEnvironment VariableDefault Value
defaultDatasetIdAPIFY_DEFAULT_DATASET_ID'default'
defaultKeyValueStoreIdAPIFY_DEFAULT_KEY_VALUE_STORE_ID'default'
defaultRequestQueueIdAPIFY_DEFAULT_REQUEST_QUEUE_ID'default'
localStorageDirAPIFY_LOCAL_STORAGE_DIR'./apify_storage'
localStorageEnableWalModeAPIFY_LOCAL_STORAGE_ENABLE_WAL_MODEtrue
persistStateIntervalMillisAPIFY_PERSIST_STATE_INTERVAL_MILLIS60e3
tokenAPIFY_TOKEN-

Advanced Configuration Options

KeyEnvironment VariableDefault Value
actorEventsWsUrlAPIFY_ACTOR_EVENTS_WS_URL-
actorIdAPIFY_ACTOR_ID-
actorRunIdAPIFY_ACTOR_RUN_ID-
actorTaskIdAPIFY_ACTOR_TASK_ID-
apiBaseUrlAPIFY_API_BASE_URL'https://api.apify.com'
containerPortAPIFY_CONTAINER_PORT4321
containerUrlAPIFY_CONTAINER_URL'http://localhost:4321'
inputKeyAPIFY_INPUT_KEY'INPUT'
isAtHomeAPIFY_IS_AT_HOME-
metamorphAfterSleepMillisAPIFY_METAMORPH_AFTER_SLEEP_MILLIS300e3
proxyHostnameAPIFY_PROXY_HOSTNAME'proxy.apify.com'
proxyPasswordAPIFY_PROXY_PASSWORD-
proxyPortAPIFY_PROXY_PORT8000
proxyStatusUrlAPIFY_PROXY_STATUS_URL'http://proxy.apify.com'
userIdAPIFY_USER_ID-

Not Supported environment variables

  • MEMORY_MBYTES
  • HEADLESS
  • XVFB
  • CHROME_EXECUTABLE_PATH

new Configuration(options)

Creates new Configuration instance with provided options. Env vars will have precedence over those.

Parameters:

  • options: Record<string, (number|string|boolean)>

configuration.storage

Provides access to the current-instance-scoped Configuration without passing it around in parameters.

Internal:


configuration.get(key, [defaultValue])

Returns configured value. First checks the environment variables, then provided configuration, fallbacks to the defaultValue argument if provided, otherwise uses the default value as described in the above section.

Parameters:

  • key: string
  • [defaultValue]: string | number | boolean

Returns:

string | number | boolean


configuration.set(key, [value])

Sets value for given option. Only affects this Configuration instance, the value will not be propagated down to the env var. To reset a value, we can omit the value argument or pass undefined there.

Parameters:

  • key: string
  • [value]: string | number | boolean

configuration.getClient([options])

Returns cached instance of ApifyClient using options as defined in the environment variables or in this Configuration instance. Only first call of this method will create the client, following calls will return the same client instance.

Caching works based on the API URL and token, so calling this method with different options will return multiple instances, one for each variant of the options.

Internal:
Parameters:

  • [options]: object
    • [token]: string
    • [maxRetries]: string
    • [minDelayBetweenRetriesMillis]: string

Returns:

ApifyClient


configuration.getStorageLocal([options])

Returns cached instance of ApifyStorageLocal using options as defined in the environment variables or in this Configuration instance. Only first call of this method will create the client, following calls will return the same client instance.

Caching works based on the storageDir option, so calling this method with different storageDir will return multiple instances, one for each directory.

Internal:
Parameters:

  • [options]: object
    • [storageDir]: string
    • [enableWalMode]: boolean = true

Returns:

ApifyStorageLocal


configuration.createClient([options])

Creates an instance of ApifyClient using options as defined in the environment variables or in this Configuration instance.

Internal:
Parameters:

  • [options]: object
    • [token]: string
    • [maxRetries]: string
    • [minDelayBetweenRetriesMillis]: string

Returns:

ApifyClient


configuration.createStorageLocal([options])

Creates an instance of ApifyStorageLocal using options as defined in the environment variables or in this Configuration instance.

Internal:
Parameters:

  • [options]: object
    • [storageDir]: string
    • [enableWalMode]: boolean = true

Returns:

ApifyStorageLocal


Configuration.getGlobalConfig()

Returns the global configuration instance. It will respect the environment variables. When used inside SDK instance (sdk.main()), the return value is equal to sdk.config.

Returns:

Configuration