M
Meshkit

Local daemon

Start or attach to a Kubo daemon automatically with localNode.

Set localNode: true to have Meshkit start or attach to a Kubo daemon on your machine. This is the recommended mode for Node.js server apps and scripts.

Minimal setup

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

const { meshkit, localNode } = await init({ localNode: true });
setupGracefulShutdown(localNode);
  • Kubo RPC URL: http://127.0.0.1:5001
  • Repo path: ./.ipfs (relative to your working directory)
  • Add .ipfs to .gitignore

Custom daemon options

Pass a StartIPFSNodeOptions object instead of true to control the daemon:

const { meshkit, localNode } = await init({
  localNode: {
    host: '127.0.0.1',
    port: 5001,
    gatewayPort: 8080,
    repo: '/data/my-ipfs-repo',
    readyTimeoutMs: 60000,
    ipfsBinary: '/usr/local/bin/ipfs',
  },
});

Attaching to an existing daemon

If a Kubo daemon is already running on the target port, Meshkit attaches to it instead of spawning a new one. localNode.managed will be false in that case.

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

if (localNode?.managed) {
  console.log('Meshkit spawned the daemon');
} else {
  console.log('Attached to existing daemon');
}

Graceful shutdown

Always register the shutdown handler so the Kubo repo is left in a consistent state on SIGINT (Ctrl+C) or SIGTERM:

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

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

setupGracefulShutdown(localNode, {
  onShutdown: async () => {
    // close your HTTP server, DB pool, etc. before Kubo stops
    await server.close();
  },
});

setupGracefulShutdown is idempotent — safe to call multiple times. Only the latest localNode and options are used.

Low-level daemon control

For scripts that need explicit lifecycle management, use startIPFSNode and stopIPFSNode directly:

import { startIPFSNode, stopIPFSNode } from '@ipfs-meshkit/meshkit';

const handle = await startIPFSNode({ repo: './.ipfs' });
// ... do work ...
await stopIPFSNode(handle);

On this page