M
Meshkit

init()

The main entry point for connecting to Kubo with optional local daemon startup.

import { init } from '@ipfs-meshkit/meshkit';

const { meshkit, localNode } = await init(options);

init() is the primary entry point for Node.js apps. It connects to one or more Kubo nodes, optionally starts a local daemon, and returns a ready-to-use Meshkit instance.

Signature

function init(options?: MeshkitBootstrapOptions): Promise<MeshkitBootstrapResult>

MeshkitBootstrapOptions

PropertyTypeDefaultDescription
nodesstring[][]Kubo RPC URLs in priority order. Optional when localNode is set.
localNodeboolean | StartIPFSNodeOptionsStart or attach to a local Kubo daemon. When true, uses 127.0.0.1:5001 and ./.ipfs repo.
headersRecord<string, string>Request headers sent to every node (e.g. RPC auth).

MeshkitBootstrapResult

PropertyTypeDescription
meshkitMeshkitConnected client with failover across healthy nodes.
localNodeIPFSNodeHandle | undefinedPresent when localNode was requested.

Examples

Local daemon

const { meshkit, localNode } = await init({ localNode: true });

Remote nodes

const { meshkit } = await init({
  nodes: ['https://kubo.example.com:5001'],
  headers: { Authorization: 'Bearer token' },
});

Local + failover

const { meshkit, localNode } = await init({
  localNode: true,
  nodes: ['https://backup.example.com:5001'],
});

Custom daemon options

const { meshkit, localNode } = await init({
  localNode: {
    port: 5001,
    repo: '/data/ipfs',
    readyTimeoutMs: 60000,
  },
});

Errors

ConditionThrown
No nodes and no localNodeMeshkitError: At least one node URL is required
All nodes unreachableMeshkitError with per-node causes
Daemon fails to startMeshkitNodeError

On this page