• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    TypeScript
  • License
    Other
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Control an IPFS daemon (go-ipfs or js-ipfs) using JavaScript!

ipfsd-ctl

ipfs.tech Discuss codecov CI

Spawn IPFS Daemons, JS or Go

Table of contents

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>

Notice

Version 1.0.0 changed a bit the api and the options methods take so please read the documentation below.

Please ensure your project also has dependencies on ipfs, ipfs-http-client, kubo-rpc-client, and go-ipfs.

npm install --save ipfs ipfs-http-client go-ipfs kubo-rpc-client

If you are only going to use the go implementation of IPFS, you can skip installing the js implementation and ipfs-http-client module. (e.g. npm i --save go-ipfs kubo-rpc-client)

If you are only using the proc type in-process IPFS node, you can skip installing go-ipfs and ipfs-http-client. (e.g. npm i --save ipfs)

You also need to explicitly defined the options ipfsBin, ipfsModule and ipfsHttpModule according to your needs. Check ControllerOptions and ControllerOptionsOverrides for more information.

Usage

Spawning a single IPFS controller: createController

This is a shorthand for simpler use cases where factory is not needed.

// No need to create a factory when only a single controller is needed.
// Use createController to spawn it instead.
const Ctl = require('ipfsd-ctl')
const ipfsd = await Ctl.createController({
    ipfsHttpModule,
    ipfsBin: goIpfsModule.path()
})
const id = await ipfsd.api.id()

console.log(id)

await ipfsd.stop()

Manage multiple IPFS controllers: createFactory

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

Spawn an IPFS daemon from Node.js

// Create a factory to spawn two test disposable controllers, get access to an IPFS api
// print node ids and clean all the controllers from the factory.
const Ctl = require('ipfsd-ctl')

const factory = Ctl.createFactory(
    {
        type: 'js',
        test: true,
        disposable: true,
        ipfsHttpModule,
        ipfsModule: (await import('ipfs')) // only if you gonna spawn 'proc' controllers
    },
    { // overrides per type
        js: {
            ipfsBin: ipfsModule.path()
        },
        go: {
            ipfsBin: goIpfsModule.path()
        }
    }
)
const ipfsd1 = await factory.spawn() // Spawns using options from `createFactory`
const ipfsd2 = await factory.spawn({ type: 'go' }) // Spawns using options from `createFactory` but overrides `type` to spawn a `go` controller

console.log(await ipfsd1.api.id())
console.log(await ipfsd2.api.id())

await factory.clean() // Clean all the controllers created by the factory calling `stop` on all of them.

Spawn an IPFS daemon from the Browser using the provided remote endpoint

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

const Ctl = require('ipfsd-ctl')

const port = 9090
const server = Ctl.createServer(port, {
    ipfsModule,
    ipfsHttpModule
},
{
    js: {
        ipfsBin: ipfsModule.path()
    },
    go: {
        ipfsBin: goIpfsModule.path()
    },
})
const factory = Ctl.createFactory({
    ipfsHttpModule,
    remote: true,
    endpoint: `http://localhost:${port}` // or you can set process.env.IPFSD_CTL_SERVER to http://localhost:9090
})

await server.start()
const ipfsd = await factory.spawn()
const id = await ipfsd.api.id()

console.log(id)

await ipfsd.stop()
await server.stop()

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, by default they create a temporary repo and automatically initialise and start the node, plus they cleanup everything when stopped.
  • non-disposable - Non disposable nodes will by default attach to any nodes running on the default or the supplied repo. Requires the user to initialize and start the node, as well as stop and cleanup afterwards.

API

createFactory([options], [overrides])

Creates a factory that can spawn multiple controllers and pre-define options for them.

Returns a Factory

createController([options])

Creates a controller.

Returns Promise<Controller>

createServer([options])

Create an Endpoint Server. This server is used by a client node to control a remote node. Example: Spawning a go-ipfs node from a browser.

  • options [Object] Factory options. Defaults to: { port: 43134 }
    • port number Port to start the server on.

Returns a Server

Factory

controllers

Controller[] List of all the controllers spawned.

tmpDir()

Create a temporary repo to create controllers manually.

Returns Promise<String> - Path to the repo.

spawn([options])

Creates a controller for a IPFS node.

Returns Promise<Controller>

clean()

Cleans all controllers spawned.

Returns Promise<Factory>

Controller

Class controller for a IPFS node.

new Controller(options)

path

String Repo path.

exec

String Executable path.

env

Object ENV object.

initialized

Boolean Flag with the current init state.

started

Boolean Flag with the current start state.

clean

Boolean Flag with the current clean state.

apiAddr

Multiaddr API address

gatewayAddr

Multiaddr Gateway address

api

Object IPFS core interface

init([initOptions])

Initialises controlled node

Returns Promise<Controller>

start()

Starts controlled node.

Returns Promise<IPFS>

stop()

Stops controlled node.

Returns Promise<Controller>

cleanup()

Cleans controlled node, a disposable controller calls this automatically.

Returns Promise<Controller>

pid()

Get the pid of the controlled node process if aplicable.

Returns Promise<number>

version()

Get the version of the controlled node.

Returns Promise<string>

ControllerOptionsOverrides

Type: [Object]

Properties

  • js [ControllerOptions] Pre-defined defaults options for JS controllers these are deep merged with options passed to Factory.spawn(options).
  • go [ControllerOptions] Pre-defined defaults options for Go controllers these are deep merged with options passed to Factory.spawn(options).
  • proc [ControllerOptions] Pre-defined defaults options for Proc controllers these are deep merged with options passed to Factory.spawn(options).

ControllerOptions

Type: [Object]

Properties

  • test [boolean] Flag to activate custom config for tests.
  • remote [boolean] Use remote endpoint to spawn the nodes. Defaults to true when not in node.
  • endpoint [string] 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 node
  • env [Object] Additional environment variables, passed to executing shell. Only applies for Daemon controllers.
  • args [Array] Custom cli args.
  • ipfsHttpModule [Object] Reference to a IPFS HTTP Client object.
  • ipfsModule [Object] Reference to a IPFS API object.
  • ipfsBin [string] Path to a IPFS exectutable.
  • ipfsOptions [IpfsOptions] Options for the IPFS instance same as https://github.com/ipfs/js-ipfs#ipfs-constructor. proc nodes receive these options as is, daemon nodes translate the options as far as possible to cli arguments.
  • forceKill [boolean] - Whether to use SIGKILL to quit a daemon that does not stop after .stop() is called. (default true)
  • forceKillTimeout [Number] - How long to wait before force killing a daemon in ms. (default 5000)

ipfsd-ctl environment variables

In additional to the API described in previous sections, ipfsd-ctl also supports several environment variables. This are often very useful when running in different environments, such as CI or when doing integration/interop testing.

Environment variables precedence order is as follows. Top to bottom, top entry has highest precedence:

  • command line options/method arguments
  • env variables
  • default values

Meaning that, environment variables override defaults in the configuration file but are superseded by options to df.spawn({...})

IPFS_JS_EXEC and IPFS_GO_EXEC

An alternative way of specifying the executable path for the js-ipfs or go-ipfs executable, respectively.

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

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.

More Repositories

1

ipfs

Peer-to-peer hypermedia protocol
22,646
star
2

kubo

An IPFS implementation in Go
Go
15,905
star
3

js-ipfs

IPFS implementation in JavaScript
JavaScript
7,438
star
4

ipfs-desktop

An unobtrusive and user-friendly desktop application for IPFS on Windows, Mac and Linux.
JavaScript
5,842
star
5

awesome-ipfs

Community list of awesome projects, apps, tools, pinning services and more related to IPFS.
JavaScript
4,307
star
6

ipfs-companion

Browser extension that simplifies access to IPFS resources on the web
JavaScript
2,010
star
7

public-gateway-checker

Checks which public gateways are online or not
TypeScript
1,697
star
8

ipfs-webui

A frontend for an IPFS node.
JavaScript
1,470
star
9

specs

Technical specifications for the IPFS protocol stack
HTML
1,107
star
10

distributed-wikipedia-mirror

Putting Wikipedia Snapshots on IPFS
TypeScript
621
star
11

helia

An implementation of IPFS in JavaScript
TypeScript
568
star
12

go-ipfs-api

The go interface to ipfs's HTTP API
Go
452
star
13

community

Discussion and documentation on community practices
Shell
416
star
14

notes

IPFS Collaborative Notebook for Research
402
star
15

go-ds-crdt

A distributed go-datastore implementation using Merkle-CRDTs.
Go
378
star
16

ipget

Retrieve files over IPFS and save them locally.
Shell
353
star
17

in-web-browsers

Tracking the endeavor towards getting web browsers to natively support IPFS and content-addressing
345
star
18

camp

🏕 IPFS Camp is a 3 day hacker retreat designed for the builders of the Distributed Web.
JavaScript
313
star
19

ipfs-docs

📚IPFS documentation platform
Go
299
star
20

roadmap

IPFS Project && Working Group Roadmaps Repo
296
star
21

team-mgmt

IPFS Team Planning, Management & Coordination threads
JavaScript
267
star
22

go-ds-s3

An s3 datastore implementation
Go
236
star
23

go-datastore

key-value datastore interfaces
Go
219
star
24

go-bitswap

The golang implementation of the bitswap protocol
Go
214
star
25

devgrants

The IPFS Grant platform connects funding organizations with builders and researchers in the IPFS community.
165
star
26

iptb

InterPlanetary TestBed 🌌🛌
Go
161
star
27

go-cid

Content ID v1 implemented in go
Go
156
star
28

boxo

A set of reference libraries for building IPFS applications and implementations in Go.
Go
148
star
29

papers

IPFS Papers (not specs)
TeX
145
star
30

ipfs-update

An updater tool for Kubo IPFS binary
Go
136
star
31

infra

Tools and systems for the IPFS community
Shell
129
star
32

go-ipfs-http-client

[archived] Legacy Kubo RPC client, use kubo/client/rpc instead.
Go
108
star
33

go-unixfs

Implementation of a unix-like filesystem on top of an ipld merkledag
Go
107
star
34

ipfs-gui

Creating standards and patterns for IPFS that are simple, accessible, reusable, and beautiful
104
star
35

go-graphsync

Initial Implementation Of GraphSync Wire Protocol
Go
100
star
36

pinning-services-api-spec

Standalone, vendor-agnostic Pinning Service API for IPFS ecosystem
Makefile
99
star
37

aegir

AEgir - Automated JavaScript project building
JavaScript
93
star
38

js-dag-service

Library for storing and replicating hash-linked data over the IPFS network.
TypeScript
93
star
39

js-ipfs-unixfs

JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)
TypeScript
85
star
40

go-merkledag

The go-ipfs merkledag 'service' implementation
Go
81
star
41

js-ipfs-repo

Implementation of the IPFS Repo spec in JavaScript
JavaScript
79
star
42

js-ipns

Utilities for creating, parsing, and validating IPNS records
TypeScript
74
star
43

js-datastore-s3

Datastore implementation with S3 backend
TypeScript
72
star
44

js-ipfs-bitswap

JavaScript implementation of Bitswap 'data exchange' protocol used by IPFS
TypeScript
65
star
45

go-ipld-format

IPLD Node and Resolver interfaces in Go
Go
61
star
46

apps

Coordinating writing apps on top of ipfs, and their concerns.
59
star
47

go-log

A logging library used by go-ipfs
Go
56
star
48

go-ipld-git

ipld handlers for git objects
Go
54
star
49

fs-repo-migrations

Migrations for the filesystem repository of ipfs clients
Go
54
star
50

go-dnslink

dnslink resolution in go-ipfs
Go
53
star
51

go-ds-badger

Datastore implementation using badger as backend.
Go
53
star
52

go-ipfs-blockstore

[ARCHIVED] This module provides a thin wrapper over a datastore and provides caching strategies.
Go
49
star
53

ipfs-blog

IPFS Blog & News
Vue
48
star
54

distributions

Legacy dist.ipfs.tech website and artifact build tools. Currently only used for notarizing builds of Kubo and IPFS Cluster.
Less
48
star
55

go-ipfs-cmds

IPFS commands package
Go
47
star
56

go-mfs

An in memory model of a mutable IPFS filesystem
Go
46
star
57

local-offline-collab

Local Offline Collaboration Special Interest Group
46
star
58

newsletter

Prepare and store the IPFS Newsletter
44
star
59

go-ds-flatfs

A datastore implementation using sharded directories and flat files to store data
Go
44
star
60

go-ipld-eth

Plugin of the Go IPFS Client for Ethereum Blockchain IPLD objects
Go
43
star
61

dht-node

[ARCHIVED] Run just an ipfs dht node (Or many nodes at once!)
Go
41
star
62

npm-kubo

Install Kubo (go-ipfs) from NPM
JavaScript
40
star
63

go-ipns

Utilities for creating, parsing, and validating IPNS records
Go
39
star
64

interface-go-ipfs-core

[ARCHIVED] this interface is now part of boxo and kubo/client/rpc
Go
38
star
65

dir-index-html

Directory listing HTML for go-ipfs gateways
HTML
38
star
66

rainbow

A specialized IPFS HTTP gateway
Go
37
star
67

go-ds-leveldb

An implementation of go-datastore using leveldb
Go
35
star
68

go-ipfs-files

An old files library, please migrate to `github.com/ipfs/go-libipfs/files` instead.
Go
33
star
69

interop

Interoperability tests for IPFS Implementations (on-the-wire interop)
JavaScript
32
star
70

ipfs-website

Official IPFS Project website
Vue
32
star
71

protons

Protocol Buffers for Node.js and the browser without eval
TypeScript
32
star
72

go-ipld-cbor

A cbor implementation of the go-ipld-format
Go
31
star
73

go-ds-sql

An implementation of ipfs/go-datastore that can be backed by any SQL database.
Go
31
star
74

go-ipfs-chunker

go-ipfs-chunkers provides Splitter implementations for data before being ingested to IPFS
Go
31
star
75

go-blockservice

The go 'blockservice' implementation, combines local and remote storage seamlessly
Go
27
star
76

service-worker-gateway

[WIP EXPERIMENT] IPFS Gateway implemented in Service Worker
TypeScript
25
star
77

go-ipld-eth-import

🌐 Bring Ethereum to IPFS 🌐
Go
25
star
78

ipld-explorer-components

React components for https://explore.ipld.io and ipfs-webui
TypeScript
24
star
79

interface-datastore

datastore interface
JavaScript
22
star
80

js-ipfs-utils

IPFS utils
JavaScript
22
star
81

metrics

Regularly collect and publish metrics about the IPFS ecosystem
JavaScript
21
star
82

js-ipfs-merkle-dag

[DEPRECATED]
JavaScript
20
star
83

js-datastore-level

Datastore implementation with level(up/down) backend
TypeScript
19
star
84

go-ipfs-example-plugin

Demo plugin for Kubo IPFS daemon
Go
19
star
85

benchmarks

Benchmarking for IPFS
JavaScript
19
star
86

ipfs-ds-convert

Command-line tool for converting datastores (e.g. from FlatFS to Badger)
Go
18
star
87

go-ipfs-provider

Go
17
star
88

js-kubo-rpc-client

A client library for the Kubo RPC API
JavaScript
17
star
89

go-pinning-service-http-client

An IPFS Pinning Service HTTP Client
Go
17
star
90

go-ipfs-gateway

Go implementation of the HTTP-to-IPFS gateway -- currently lives in go-ipfs
16
star
91

go-ipld-zcash

An implementation of the zcash block and transaction datastructures for ipld
Go
16
star
92

ipfs-camp-2022

Conference content and other resources for IPFS Camp 2022 in Lisbon, Portugal
16
star
93

go-ipfs-config

[ARCHIVED] config is now part of go-ipfs repo
Go
16
star
94

mobile-design-guidelines

Making IPFS work for mobile
15
star
95

js-datastore-core

Contains various implementations of the API contract described in interface-datastore
TypeScript
15
star
96

ecosystem-directory

Interactive showcase of projects and products built using IPFS, the InterPlanetary File System.
HTML
15
star
97

js-datastore-fs

Datastore implementation with file system backend
TypeScript
14
star
98

go-namesys

go-namesys provides publish and resolution support for the /ipns/ namespace in go-ipfs
Go
14
star
99

helia-unixfs

UnixFS commands for helia
TypeScript
14
star
100

js-stores

TypeScript interfaces used by IPFS internals
TypeScript
14
star