Skip to main content
Version: 3.0

Configuration

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

  1. When using Actor class, we can get the instance configuration via sdk.config
    import { Actor } from 'apify';
    import { BasicCrawler } from 'crawlee';

    const sdk = new Actor({ token: '123' });
    console.log(sdk.config.get('token')); // '123'

    const crawler = new BasicCrawler({
    // ... crawler options
    }, sdk.config);
  2. To get the global configuration (singleton instance). It will respect the environment variables.
    import { BasicCrawler, Configuration } from 'crawlee';

    // Get the global configuration
    const config = Configuration.getGlobalConfig();
    // Set the 'persistStateIntervalMillis' option
    // of global configuration to 30 seconds
    config.set('persistStateIntervalMillis', 30_000);

    // No need to pass the configuration to the crawler,
    // as it's using the global configuration by default
    const crawler = new BasicCrawler();

Supported Configuration Options

KeyEnvironment VariableDefault Value
memoryMbytesAPIFY_MEMORY_MBYTES-
headlessAPIFY_HEADLESS-
persistStateIntervalMillisAPIFY_PERSIST_STATE_INTERVAL_MILLIS60e3
tokenAPIFY_TOKEN-
isAtHomeAPIFY_IS_AT_HOME-
defaultDatasetIdAPIFY_DEFAULT_DATASET_ID'default'
defaultKeyValueStoreIdAPIFY_DEFAULT_KEY_VALUE_STORE_ID'default'
defaultRequestQueueIdAPIFY_DEFAULT_REQUEST_QUEUE_ID'default'

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'
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-
xvfbAPIFY_XVFB-
chromeExecutablePathAPIFY_CHROME_EXECUTABLE_PATH-
defaultBrowserPathAPIFY_DEFAULT_BROWSER_PATH-

Hierarchy

  • Configuration
    • Configuration

Index

Constructors

externalconstructor

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


    Parameters

    • externaloptionaloptions: ConfigurationOptions

    Returns Configuration

Properties

staticoptionalglobalConfig

globalConfig?: Configuration
@inheritDoc

Methods

get

  • get<T, U>(key: T, defaultValue?: U): U
  • @inheritDoc

    Type parameters

    • T: keyof ConfigurationOptions
    • U: undefined | string | number | boolean | StorageClient | EventManager | Dictionary<any> | (radix?: number) => string | (fractionDigits?: number) => string | (fractionDigits?: number) => string | (precision?: number) => string | () => number | ({ (locales?: string | string[], options?: NumberFormatOptions): string; (locales?: LocalesArgument, options?: NumberFormatOptions): string })

    Parameters

    • key: T
    • optionaldefaultValue: U

    Returns U

externalgetEventManager

  • getEventManager(): EventManager
  • Returns EventManager

set

  • @inheritDoc

    Parameters

    Returns void

externaluseEventManager

  • useEventManager(events: EventManager): void
  • Parameters

    • externalevents: EventManager

    Returns void

externaluseStorageClient

  • useStorageClient(client: StorageClient): void
  • Parameters

    • externalclient: StorageClient

    Returns void

staticexternalgetEventManager

  • getEventManager(): EventManager
  • Gets default EventManager instance.


    Returns EventManager

staticgetGlobalConfig

  • @inheritDoc

    Returns Configuration

staticexternalgetStorageClient

  • getStorageClient(): StorageClient
  • Gets default StorageClient instance.


    Returns StorageClient

staticresetGlobalState

  • resetGlobalState(): void
  • Resets global configuration instance. The default instance holds configuration based on env vars, if we want to change them, we need to first reset the global state. Used mainly for testing purposes.


    Returns void