init

init()
init(url)
init(options)

Asynchronously initialize the dcp-client bundle for use by the compute API, etc.

Arguments:
  • url (string|URL) – Form 2. Scheduler URL location. Equivalent to init({ scheduler: url }).

  • options (object) – Form 3. An options object – see below.

Return type:

Promise<object> – an object whose properties are the loaded dcp/* modules (compute, wallet, worker, protocol, identity, jnu, etc.), each already require()-able as dcp/<name> from this point on.

Note

There is no positional autoUpdate/bundleLocation form. init() only ever takes zero or one argument (a scheduler URL string/URL, or an options object) – a second positional argument is only accepted for a deprecated form (init(dcpConfigFragment, options)) that predates the options.dcpConfig property below and should not be used in new code. Calling init(url, someBoolean), as earlier revisions of this page suggested, does not set autoUpdate at all – it’s silently misinterpreted as the deprecated two-argument form.

Options object properties (Form 3), all optional:

  • scheduler (string|URL) - Scheduler location. Defaults to https://scheduler.distributed.computer/.

  • autoUpdate (boolean) - When true, downloads a fresh dcp-client bundle from the scheduler at startup rather than using the bundle already installed locally.

  • bundleLocation (string|URL) - Where to download the auto update bundle from, if autoUpdate is set. Defaults to a location derived from scheduler.

  • parseArgv (boolean) - When false, skips parsing --dcp-* command-line options (for example, --dcp-scheduler=...) out of process.argv. Defaults to true, unless the DCP_CLIENT_NO_PARSE_ARGV environment variable is set.

  • reportErrors (boolean) - When false, initialization errors (for example, failure to download the auto update bundle) are thrown instead of logged to console.error with a process.exit(1).

  • configName (string) - Name used to resolve a local config-fragment filename, relative to the program module.

  • dcpConfig (object) - A dcpConfig fragment merged in as part of the default configuration.

  • enableSourceMaps (boolean) - Installs source-map-support for more legible error stack traces. Same effect as the DCP_CLIENT_ENABLE_SOURCEMAPS environment variable.

Example:

async function main() {
  /* DCP App ... */
}

require('dcp-client').init().then(main);

Tutorials: