Config API

June 15, 2020 ยท View on GitHub

ipfs.config.get(key, [options])

Returns the currently being used config. If the daemon is off, it returns the stored config.

Parameters

NameTypeDescription
keyStringThe key of the value that should be fetched from the config file.

Options

An optional object which may have the following keys:

NameTypeDefaultDescription
timeoutNumberundefinedA timeout in ms
signalAbortSignalundefinedCan be used to cancel any long running requests started as a result of this call

Returns

TypeDescription
Promise<Object>An object containing the configuration of the IPFS node

Example

const config = await ipfs.config.get()
console.log(config)

A great source of examples can be found in the tests for this API.

ipfs.config.getAll([options])

Returns the full config been used. If the daemon is off, it returns the stored config.

Options

An optional object which may have the following keys:

NameTypeDefaultDescription
timeoutNumberundefinedA timeout in ms
signalAbortSignalundefinedCan be used to cancel any long running requests started as a result of this call

Returns

TypeDescription
Promise<Object>An object containing the configuration of the IPFS node

Example

const config = await ipfs.config.getAll()
console.log(config)

A great source of examples can be found in the tests for this API.

ipfs.config.set(key, value, [options])

Adds or replaces a config value.

Parameters

NameTypeDescription
keyStringThe key of the value that should be added or replaced
valueanyThe value to be set

Options

An optional object which may have the following keys:

NameTypeDefaultDescription
timeoutNumberundefinedA timeout in ms
signalAbortSignalundefinedCan be used to cancel any long running requests started as a result of this call

Returns

TypeDescription
Promise<void>If action is successfully completed. Otherwise an error will be thrown

Note that this operation will not spark the restart of any service, i.e: if a config.replace changes the multiaddrs of the Swarm, Swarm will have to be restarted manually for the changes to take difference.

Example

await ipfs.config.set('Discovery.MDNS.Enabled', false)
// MDNS Discovery was set to false

A great source of examples can be found in the tests for this API.

ipfs.config.replace(config, [options])

Adds or replaces a config file

Parameters

NameTypeDescription
configObjectAn object that contains the new config

Options

An optional object which may have the following keys:

NameTypeDefaultDescription
timeoutNumberundefinedA timeout in ms
signalAbortSignalundefinedCan be used to cancel any long running requests started as a result of this call

Returns

TypeDescription
Promise<void>If action is successfully completed. Otherwise an error will be thrown

Note that this operation will not spark the restart of any service, i.e: if a config.replace changes the multiaddrs of the Swarm, Swarm will have to be restarted manually for the changes to take difference.

Example

const newConfig = {
  Bootstrap: []
}

await ipfs.config.replace(newConfig)
// config has been replaced

A great source of examples can be found in the tests for this API.

ipfs.config.profiles.list([options])

List available config profiles

Parameters

None

Options

An optional object which may have the following keys:

NameTypeDefaultDescription
timeoutNumberundefinedA timeout in ms
signalAbortSignalundefinedCan be used to cancel any long running requests started as a result of this call

Returns

TypeDescription
Promise<Array>An array with all the available config profiles

Example

const profiles = await ipfs.config.profiles.list()
profiles.forEach(profile => {
  console.info(profile.name, profile.description)
})

A great source of examples can be found in the tests for this API.

ipfs.config.profiles.apply(name, [options])

Apply a config profile

Parameters

NameTypeDescription
nameStringThe name of the profile to apply

Call config.profiles.list() for a list of valid profile names.

Options

An optional object which may have the following keys:

NameTypeDefaultDescription
dryRunbooleanfalseIf true does not apply the profile
timeoutNumberundefinedA timeout in ms
signalAbortSignalundefinedCan be used to cancel any long running requests started as a result of this call

Returns

TypeDescription
Promise<Object>An object containing both the original and updated config

Example

const diff = await ipfs.config.profiles.apply('lowpower')
console.info(diff.original)
console.info(diff.updated)

Note that you will need to restart your node for config changes to take effect.

A great source of examples can be found in the tests for this API.