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
| Property | Type | Default | Description |
|---|---|---|---|
host | string | "127.0.0.1" | Kubo RPC API host. |
port | number | 5001 | Kubo RPC API port. |
gatewayPort | number | 8080 | HTTP gateway port. |
repo | string | ./.ipfs | Filesystem path for the Kubo repo (IPFS_PATH). |
init | boolean | true | Pass --init so a missing repo is initialized automatically. |
readyTimeoutMs | number | 30000 | Max ms to wait for the RPC API to become healthy. |
ipfsBinary | string | "ipfs" | Kubo binary name or absolute path. |
IPFSNodeHandle
| Property | Type | Description |
|---|---|---|
url | string | Kubo RPC URL, e.g. http://127.0.0.1:5001. |
repo | string | undefined | Repo path when Meshkit spawned the daemon. |
managed | boolean | true 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,
): voidRegister 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
| Property | Type | Default | Description |
|---|---|---|---|
onShutdown | () => void | Promise<void> | — | Runs before Kubo stops. Close HTTP servers, DB pools, etc. |
exit | boolean | true | Exit the process after shutdown. |
exitCode | number | 0 | Process 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,
});