Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ipfsd-ctl

ipfs10.4kApache-2.0 OR MIT15.0.2TypeScript support: included

Spawn IPFS Daemons, Kubo or...

daemon, ipfs, node

readme

ipfsd-ctl

ipfs.tech Discuss codecov CI

Spawn IPFS Daemons, Kubo or...

About

This module allows you to spawn long-lived IPFS implementations from any JS environment and interact with the as is they were in the local process.

It is designed mostly for testing interoperability and is not suitable for production use.

Spawning a single noder: createNode

Example - Spawning a Kubo node

import { createNode } from 'ipfsd-ctl'
import { path } from 'kubo'
import { create } from 'kubo-rpc-client'

const node = await createNode({
  type: 'kubo',
  rpc: create,
  bin: path()
})

console.info(await node.api.id())

Manage multiple nodes: createFactory

Use a factory to spawn multiple nodes based on some common template.

Example - Spawning multiple Kubo nodes

import { createFactory } from 'ipfsd-ctl'
import { path } from 'kubo'
import { create } from 'kubo-rpc-client'

const factory = createFactory({
  type: 'kubo',
  rpc: create,
  bin: path()
})

const node1 = await factory.spawn()
const node2 = await factory.spawn()
//...etc

// later stop all nodes
await factory.clean()

Override config based on implementation type

createFactory takes a second argument that can be used to pass default options to an implementation based on the type field.

import { createFactory } from 'ipfsd-ctl'
import { path } from 'kubo'
import { create } from 'kubo-rpc-client'

const factory = createFactory({
  type: 'kubo',
  test: true
}, {
  otherImpl: {
    //...other impl args
  }
})

const kuboNode = await factory.spawn()
const otherImplNode = await factory.spawn({
  type: 'otherImpl'
})

Spawning nodes from browsers

To spawn nodes from browsers, first start an ipfsd-ctl server from node.js and make the address known to the browser (the default way is to set process.env.IPFSD_CTL_SERVER in your bundle):

Example - Create server

In node.js:

// Start a remote disposable node, and get access to the api
// print the node id, and stop the temporary daemon

import { createServer } from 'ipfsd-ctl'

const port = 9090
const server = createServer(port, {
  type: 'kubo',
  test: true
}, {
   // overrides
})
await server.start()

In a browser:

import { createFactory } from 'ipfsd-ctl'

const factory = createFactory({
  // or you can set process.env.IPFSD_CTL_SERVER to http://localhost:9090
  endpoint: `http://localhost:${port}`
})

const node = await factory.createNode({
  type: 'kubo'
})
console.info(await node.api.id())

Disposable vs non Disposable nodes

ipfsd-ctl can spawn disposable and non-disposable nodes.

  • disposable- Disposable nodes are useful for tests or other temporary use cases, they create a temporary repo which is deleted automatically when the node is stopped
  • non-disposable - Disposable nodes will not delete their repo when stopped

Install

$ npm i ipfsd-ctl

Browser <script> tag

Loading this module through a script tag will make it's exports available as IpfsdCtl in the global namespace.

<script src="https://unpkg.com/ipfsd-ctl/dist/index.min.js"></script>

API Docs

License

Licensed under either of

Contribute

Contributions welcome! Please check out the issues.

Also see our contributing document for more information on how we work, and about contributing in general.

Please be aware that all interactions related to this repo are subject to the IPFS Code of Conduct.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

changelog

15.0.2 (2024-11-21)

Bug Fixes

  • return gateway href in .info response (#850) (c9dafd0)

15.0.1 (2024-11-14)

Dependencies

  • dev: bump aegir from 44.1.4 to 45.0.1 (#848) (93dd0e5)
  • dev: bump kubo from 0.30.0 to 0.32.0 (#849) (f1f9f5c)

15.0.0 (2024-09-12)

⚠ BREAKING CHANGES

Bug Fixes

14.1.3 (2024-09-12)

Bug Fixes

14.1.2 (2024-09-12)

Dependencies

  • dev: bump kubo from 0.28.0 to 0.30.0 (#843) (c1ca2a4)

14.1.1 (2024-09-12)

Dependencies

  • dev: bump aegir from 42.2.11 to 44.1.0 (#842) (26aea4a)

14.1.0 (2024-04-26)

Features

14.0.6 (2024-04-19)

Bug Fixes

  • add retries to repo deletion because windows (8ac86d9)

14.0.5 (2024-04-19)

Bug Fixes

14.0.4 (2024-04-19)

Bug Fixes

14.0.3 (2024-04-19)

Bug Fixes

Trivial Changes

14.0.2 (2024-04-19)

Bug Fixes

14.0.1 (2024-04-19)

Bug Fixes

  • use configured endpoint instead of default (#824) (e0d2f88)

14.0.0 (2024-04-19)

⚠ BREAKING CHANGES

  • only supports spawning kubo daemons

Features

Trivial Changes

  • add or force update .github/workflows/js-test-and-release.yml (#819) (f60600d)
  • delete templates [skip ci] (#818) (a98af4b)
  • remove extra dirs (eb293bf)
  • Update .github/workflows/stale.yml [skip ci] (9f261e3)
  • Update .github/workflows/stale.yml [skip ci] (4fa7fdc)
  • Update .github/workflows/stale.yml [skip ci] (bbd17c6)

Documentation

13.0.0 (2023-01-13)

⚠ BREAKING CHANGES

  • update all deps to multiformats 11 (#801)

Dependencies

12.2.2 (2022-10-19)

Bug Fixes

12.2.1 (2022-10-07)

Dependencies

  • dev: bump go-ipfs from 0.15.0 to 0.16.0 (#779) (c3301f1)

12.2.0 (2022-10-05)

Features

12.1.1 (2022-10-05)

Bug Fixes

  • update export path to point to correct file (#778) (ecdda55)

12.1.0 (2022-10-04)

Features

12.0.3 (2022-09-21)

Dependencies

  • update @multiformats/multiaddr to 11.0.0 (#775) (087e80c)

12.0.2 (2022-09-02)

Bug Fixes

  • make sure to behave as node.js in electron main process (#761) (9492643), closes #760

12.0.1 (2022-09-01)

Trivial Changes

  • Update .github/workflows/stale.yml [skip ci] (8bf29d3)
  • update project config (#768) (29c44cb)

Dependencies

12.0.0 (2022-06-28)

⚠ BREAKING CHANGES

  • pulls in new peer-id interface

Features

11.0.1 (2022-05-25)

Trivial Changes

  • bump @libp2p/interfaces from 1.3.32 to 2.0.2 (#734) (cc91981)

11.0.0 (2022-05-09)

⚠ BREAKING CHANGES

  • the controller.api.peerId property is now at controller.peer

Features

10.0.6 (2022-02-22)

Features

10.0.5 (2021-11-19)

Bug Fixes

  • silence deprecation warning for fs.rmdir (#697) (45ef5ca)

10.0.4 (2021-09-28)

10.0.3 (2021-08-04)

10.0.2 (2021-08-03)

Bug Fixes

10.0.1 (2021-07-30)

Bug Fixes

10.0.0 (2021-07-30)

Features

BREAKING CHANGES

  • things are now typed which may be suprising

9.0.0 (2021-07-10)

chore

BREAKING CHANGES

  • Use new multiaddr class

8.0.2 (2021-04-17)

8.0.1 (2021-04-09)

8.0.0 (2021-03-26)

chore

BREAKING CHANGES

  • expects ipfs-http-client and ipfs-client to export a .create function

7.2.0 (2020-12-18)

Features

7.1.1 (2020-12-03)

7.1.0 (2020-10-28)

Features

7.0.3 (2020-10-23)

Bug Fixes

  • kill disposable nodes on stop and simplify started status (#554) (cd123cc)

7.0.2 (2020-10-10)

Bug Fixes

Features

7.0.1 (2020-09-17)

Bug Fixes

7.0.0 (2020-08-25)

Chores

BREAKING CHANGES

    • Hapi has dropped support for node < 12

6.0.0 (2020-08-12)

5.0.0 (2020-07-16)

Features

BREAKING CHANGES

  • Previously dependent projects should also depend on go-ipfs-dep, now they should depend on go-ipfs instead

4.1.1 (2020-05-13)

Bug Fixes

  • remove onBlocked hook from delete database (#509) (e4d6f80)

4.1.0 (2020-04-29)

Features

  • remove default key size and upgrade go-ipfs (#504) (ecbf4be)

4.0.2 (2020-04-29)

Bug Fixes

  • pin go-ipfs to 0.4.23-3 (11976f1)

4.0.1 (2020-04-20)

Bug Fixes

  • remove aegir from production code (61b5ea5), closes #501

4.0.0 (2020-04-20)

Bug Fixes

  • move IPFS_PATH test to a node specific file (9d9cedd)
  • revert boom and hapi (a92177f)
  • use IPFS_PATH env var (708c7cc), closes #497

Features

  • ipfsd-ctl server can find free ports (db64997)
  • update deps and remove support for node 8 (2565199)

BREAKING CHANGES

  • node 8 support removed

3.1.0 (2020-04-14)

Bug Fixes

3.0.0 (2020-02-10)

Code Refactoring

  • remove option normalisation (#454) (f1e5c82)
  • remove path and ref from module args also findBin (#458) (7049cc9)

BREAKING CHANGES

    • .path and .ref args removed from ipfsModule and ipfsHttpModule
  • findBin function removed

  • chore: update dep versions

  • chore: increase test timeouts

  • fix: only get go-ipfs path in node

  • fix: linting

Co-authored-by: Alex Potsides alex@achingbrain.net

  • ipfsd-ctl no longer defaults to a local ipfs, ipfs-http-client or ipfs bin, now the user needs to set those packages when creating controllers and remote controller server.

2.1.0 (2020-01-31)

Bug Fixes

2.0.0 (2020-01-29)

Bug Fixes

Features

BREAKING CHANGES

  • This package now requires the user to bring their own version, but they can also skip installing go-IPFS if, for example, they are only going to use js-IPFS.

1.0.7 (2020-01-24)

1.0.6 (2020-01-17)

Bug Fixes

  • find bin top to bottom instead of the inverse (bc847fb)

1.0.5 (2020-01-16)

1.0.4 (2020-01-16)

Bug Fixes

1.0.3 (2020-01-16)

Bug Fixes

  • add endpoint option to the docs (3e61a00)
  • set profiles option if profiles array not empty (#433) (12a2b6c)

1.0.2 (2019-12-11)

1.0.0 (2019-12-11)

Features

BREAKING CHANGES

  • Problems:
  • Browsers tests skipped cause ctl didn't support proper connectivity to remote nodes
  • We weren't able to tell ctl to use a specific commit of http-client, js-ipfs or cli
  • Options/config between the 3 types of daemons weren't consistent
  • Ctl didn't support remote "in process" daemon
  • IPFS options were handled manually inside ctl, so any change in js-ipfs would require a PR in ctl to support the new options or change to an option

Related issues:

Improvements:

  • better errors
  • DEBUG='ipfsd-ctl:*' everywhere
  • factories for tests with good defaults
  • options are properly merged everywhere
  • safer child_process exit stop()
  • faster stop()
  • IPFS Options are now the same format as https://github.com/ipfs/js-ipfs/blob/master/README.md#ipfs-constructor
  • Ctl can init, start and set config in one cmd (at least with js-ipfs)
  • better docs and jsdocs
  • we can now be sure which http-client, ipfs or go-ipfs is being used
  • utils functions actually work in the browser now
  • works in webworkers now
  • simpler and faster overall
  • disposable node actually clean themselves in the browser
  • better tests
  • ...
  • support electron
  • test in electron

New:

  • new method createController returns a spawned controller
  • createFactory as a second parameter to override options per type

Changes:

  • create change to createFactory
  • createFactory options changed

Old

- `options` - optional object with:
  - `remote` bool - use remote endpoint to spawn the nodes.
  - `port` number - remote endpoint port. Defaults to 43134.
  - `exec` - IPFS executable path. `ipfsd-ctl` will attempt to locate it by default. If you desire to spawn js-ipfs instances in the same process, pass the ref to the module instead (e.g `exec: require('ipfs')`)
  - `type` - the daemon type, see below the options
    - `go` - spawn go-ipfs daemon
    - `js` - spawn js-ipfs daemon
    - `proc` - spawn in-process js-ipfs instance. Needs to be called also with exec. Example: `DaemonFactory.create({type: 'proc', exec: require('ipfs') })`.
  - `IpfsClient` - A custom IPFS API constructor to use instead of the packaged one

New

-   `remote` [boolean] Use remote endpoint to spawn the nodes. Defaults to `true` when not in node.
-   `test` [test=false] - Flag to activate custom config for tests.
-   `endpoint` [endpoint] - Endpoint URL to manage remote Controllers. (Defaults: 'http://localhost:43134').
-   `disposable` [Boolean] A new repo is created and initialized for each invocation, as well as cleaned up automatically once the process exits.
-   `type` [string] The daemon type, see below the options:-   go - spawn go-ipfs daemon
    -   js - spawn js-ipfs daemon
    -   proc - spawn in-process js-ipfs instance
-   `env` [Object] Additional environment variables, passed to executing shell. Only applies for Daemon controllers.
-   `args` [Array] Custom cli args.
-   `ipfsHttp` [Object] Setup IPFS HTTP client to be used by ctl.
    -   `ipfsHttp.ref` [Object] Reference to a IPFS HTTP Client object. (defaults to the local require(`ipfs-http-client`))
    -   `ipfsHttp.path` [string] Path to a IPFS HTTP Client to be required. (defaults to the local require.resolve('ipfs-http-client'))
-   `ipfsApi` [Object] Setup IPFS API to be used by ctl.
    -   `ipfsApi.ref` [Object] Reference to a IPFS API object. (defaults to the local require(`ipfs`))
    -   `ipfsApi.path` [string] Path to a IPFS API implementation to be required. (defaults to the local require.resolve('ipfs'))
-   `ipfsBin` [String] Path to a IPFS exectutable . (defaults to the local 'js-ipfs/src/bin/cli.js')
-   `ipfsOptions` [IpfsOptions] Options for the IPFS instance
  • Previous default ipfs config is only applied when test options equals true
  • defaultAddrs option was removed
  • Spawn options are the same as createFactory

Old

- `options` is an optional object the following properties:
  - `init` bool (default true) or Object - should the node be initialized
  - `initOptions` object - should be of the form `{bits: <size>}`, which sets the desired key size
  - `start` bool (default true) - should the node be started
  - `repoPath` string - the repository path to use for this node, ignored if node is disposable
  - `disposable` bool (default true) - a new repo is created and initialized for each invocation, as well as cleaned up automatically once the process exits
  - `defaultAddrs` bool (default false) - use the daemon default `Swarm` addrs
  - `args` - array of cmd line arguments to be passed to ipfs daemon
  - `config` - ipfs configuration options

NEW Same as js-ipfs constructor https://github.com/ipfs/js-ipfs#ipfs-constructor

  • ipfsd.killProcess removed not needed anymore
  • ipfsd.getConfig removed call ipfsd.api.config.get instead
  • ipfsd.setConfig removed, call ipfsd.api.config.set instead

Read the README for documention on the new api and options

0.47.4 (2019-10-14)

Bug Fixes

0.47.3 (2019-10-10)

Bug Fixes

0.47.2 (2019-09-20)

0.47.1 (2019-09-18)

Bug Fixes

  • use local options instead of instance to check "exec" (38a730d)

0.47.0 (2019-09-18)

Bug Fixes

0.46.3 (2019-09-15)

0.46.2 (2019-09-15)

Bug Fixes

0.46.1 (2019-09-11)

Bug Fixes

  • make proc silent by default (a62bd97)

0.46.0 (2019-09-05)

Features

BREAKING CHANGES

  • pubsub flags for in-proc daemons will not set values anymore

0.45.1 (2019-09-03)

0.45.0 (2019-09-02)

Features

BREAKING CHANGES

  • removes the experimental flag of pubsub and makes it enable by default

0.44.2 (2019-08-30)

0.44.1 (2019-07-11)

0.44.0 (2019-07-05)

Features

0.43.0 (2019-06-20)

Bug Fixes

  • updates deps and http for name resolve dns (#332) (58a9fea)

0.42.4 (2019-06-04)

0.42.3 (2019-05-17)

Bug Fixes

  • dont call callbacks twice (c61606f)

0.42.2 (2019-04-04)

Bug Fixes

0.42.1 (2019-03-20)

Bug Fixes

  • remove relay and mfs from experimental (#325) (c42c960)

Features

0.42.0 (2019-02-12)

Features

0.41.0 (2019-01-30)

Bug Fixes

BREAKING CHANGES

  • --local option has been renamed to --offline

0.40.3 (2019-01-04)

0.40.2 (2018-12-11)

0.40.1 (2018-11-28)

Features

0.40.0 (2018-11-03)

Features

  • go-ipfs 0.4.18 and js-ipfs 0.33.0 (503ef42)

0.39.5 (2018-10-28)

Bug Fixes

Features

  • add dht experimental flag (3164a88)
  • use execa instead of subcomandante (388b401)

0.39.4 (2018-10-26)

Bug Fixes

0.39.3 (2018-10-19)

Bug Fixes

  • CLI scraping of API and Gateway addresses (#301) (1fc3fa0)

Features

0.39.2 (2018-09-12)

Bug Fixes

0.39.1 (2018-08-07)

Features

  • allows a custom IpfsApi constructor to be used (#261) (dacde26)
  • go-ipfs 0.4.17 (958a9e3)

0.39.0 (2018-07-28)

Features

0.38.0 (2018-07-15)

0.37.5 (2018-06-22)

Bug Fixes

Features

0.37.4 (2018-06-11)

Features

0.37.3 (2018-06-01)

0.37.2 (2018-06-01)

0.37.1 (2018-06-01)

Features

  • add support for experimental mfs flag (3ce834e)

0.37.0 (2018-05-23)

0.36.0 (2018-05-17)

Features

0.35.0 (2018-05-17)

Features

0.34.0 (2018-05-14)

0.33.2 (2018-05-08)

0.33.1 (2018-05-06)

Bug Fixes

  • Daemon spawning throws error with the new multiaddr version (a0d2e37)

0.33.0 (2018-05-04)

Bug Fixes

0.32.1 (2018-04-12)

0.32.0 (2018-04-06)

Features

0.31.0 (2018-03-27)

Features

  • upgrade to go-ipfs-0.4.14 (77b4cd9)

0.30.4 (2018-03-21)

Features

0.30.3 (2018-03-16)

Bug Fixes

  • daemon should recognize previously created repos. (#212) (2e9cf0d)

0.30.2 (2018-03-16)

Bug Fixes

  • pass on environment variables (b73325e)

0.30.1 (2018-03-15)

Bug Fixes

  • pass keysize on command line (e2a6697)

0.30.0 (2018-03-14)

Features

0.29.1 (2018-02-23)

Bug Fixes

0.29.0 (2018-02-21)

Bug Fixes

  • don't pass on arguments from node executable (cf794cd), closes #202

Features

  • add keysize through an option to spawn (#203) (151303c)

0.28.0 (2018-02-12)

Bug Fixes

  • make sure repo is being properly cleaned up (#196) (4e8b8db)

Features

0.27.3 (2018-01-30)

Features

0.27.2 (2018-01-27)

Features

  • support for passphrase for js-ipfs daemons (3bc94c1)

0.27.1 (2018-01-21)

Bug Fixes

  • make sure exec matches the passed node type (#184) (89e9059)

0.27.0 (2018-01-16)

0.26.1 (2018-01-16)

Features

  • Complete revamp! Spawn js/go daemons locally or remote (from the browser) (#176) (1cfbd08)

0.26.0 (2017-12-01)

0.25.1 (2017-11-22)

Features

  • accept flags as an object as well (8cb9d01)

0.25.0 (2017-11-22)

0.24.1 (2017-11-12)

Features

0.24.0 (2017-10-18)

0.23.0 (2017-09-06)

Features

  • replaces path to .asar.unpacked + windows support (a44cb79)
  • Slay the Dragon! (#165) (80377cd)

0.22.0 (2017-09-02)

Bug Fixes

Features

0.21.0 (2017-05-19)

Bug Fixes

  • remove possible overlapping of tmp folder (54a96a8)

Features

  • update to use go-ipfs v0.4.9 and latest ipfs-block (94f0a97)

0.20.0 (2017-03-20)

Features

  • v0.4.7 and update aegir and its lintness (eadf560)

0.19.0 (2017-02-16)

0.18.3 (2017-02-09)

0.18.2 (2017-01-31)

0.18.1 (2017-01-04)

Bug Fixes

0.18.0 (2016-12-23)

Bug Fixes

  • fail gracefully when config file is not found (a200a15)

Features

  • init: Add the possibility to pass options to init() (9c48373)
  • better stream handling (#140) (a0adc82)

0.17.0 (2016-10-29)

0.16.0 (2016-09-29)

Bug Fixes

  • ensure setting the config cbs only once (e44a8ac)

Features

  • upgrade to go-ipfs 0.4.3 (a2ebc1a)

0.15.0 (2016-09-16)

Bug Fixes

  • shutdown: fixed bugs in stopDaemon (af21eb0)
  • startDaemon: fix the behavior of startDeamon (0deb7e5)
  • test: change hash of src test (349a44c)
  • make the linter happy for D# (9a5c0e2)
  • rm unused var (thanks, linter) (6d21086)
  • tests: guarded func to avoid it being called twice (2c8a3c1)

Features

  • startDeamon: allow passing flags to ipfs daemon (c7ea808)

0.14.0 (2016-05-18)

Features

  • upgrade dependencies to latest (0231951)

0.13.0 (2016-05-01)

0.12.0 (2016-04-27)

0.11.0 (2016-04-22)

0.10.1 (2016-04-11)

0.10.0 (2016-04-09)

0.9.1 (2016-04-08)

0.9.0 (2016-04-08)

0.8.1 (2016-01-31)

0.8.0 (2016-01-22)

Features

0.7.1 (2015-12-18)

0.6.3 (2015-11-14)

0.6.2 (2015-11-14)

Features

  • Add configurable $IPFS_EXEC (5aa011b)
  • Require node.js >= 4 (f25143b)

0.6.1 (2015-11-02)

Bug Fixes

  • Switch shutdown handler library (491268b), closes #19

0.6.0 (2015-10-31)

0.5.6 (2015-10-29)

0.5.5 (2015-10-24)

0.5.4 (2015-10-16)

0.5.3 (2015-10-16)

0.5.2 (2015-10-11)

0.5.1 (2015-09-25)

0.5.0 (2015-09-18)

0.4.1 (2015-09-18)