M
Meshkit

Node API

startIPFSNode, stopIPFSNode, setupGracefulShutdown — low-level daemon control.

startIPFSNode

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

const handle = await startIPFSNode(options?: StartIPFSNodeOptions): Promise<IPFSNodeHandle>

Start or attach to a local Kubo daemon. Called automatically when you pass localNode to init(). Use directly when you need explicit lifecycle control.

StartIPFSNodeOptions

PropertyTypeDefaultDescription
hoststring"127.0.0.1"Kubo RPC API host.
portnumber5001Kubo RPC API port.
gatewayPortnumber8080HTTP gateway port.
repostring./.ipfsFilesystem path for the Kubo repo (IPFS_PATH).
initbooleantruePass --init so a missing repo is initialized automatically.
readyTimeoutMsnumber30000Max ms to wait for the RPC API to become healthy.
ipfsBinarystring"ipfs"Kubo binary name or absolute path.

IPFSNodeHandle

PropertyTypeDescription
urlstringKubo RPC URL, e.g. http://127.0.0.1:5001.
repostring | undefinedRepo path when Meshkit spawned the daemon.
managedbooleantrue if Meshkit spawned the daemon; false if attached to existing.
stop()() => Promise<void>Stop the daemon (only meaningful when managed: true).

stopIPFSNode

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

await stopIPFSNode(handle: IPFSNodeHandle): Promise<void>

Stop a managed Kubo daemon. No-op if handle.managed is false.


setupGracefulShutdown

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

setupGracefulShutdown(
  localNode: IPFSNodeHandle | undefined,
  options?: GracefulShutdownOptions,
): void

Register SIGINT and SIGTERM handlers that stop a managed Kubo daemon cleanly. Safe to call multiple times — handlers are registered once; the latest localNode and options win.

GracefulShutdownOptions

PropertyTypeDefaultDescription
onShutdown() => void | Promise<void>Runs before Kubo stops. Close HTTP servers, DB pools, etc.
exitbooleantrueExit the process after shutdown.
exitCodenumber0Process exit code.

Example

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

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

setupGracefulShutdown(localNode, {
  onShutdown: async () => {
    await httpServer.close();
  },
  exitCode: 0,
});

On this page