@ipfs-meshkit/meshkit is a Node.js SDK for Kubo (IPFS). Upload, retrieve, and pin content over Kubo’s HTTP RPC, with optional local daemon startup, IPNS, and multi-node failover.
npm install @ipfs-meshkit/meshkitRequirements: Node.js 20+. For localNode: true, install Kubo and ensure ipfs is on your PATH.
import { init, setupGracefulShutdown } from '@ipfs-meshkit/meshkit';
const { meshkit, localNode } = await init({ localNode: true });
setupGracefulShutdown(localNode);
const bytes = new TextEncoder().encode('hello');
const cid = await meshkit.upload(bytes);
await meshkit.pin(cid);
const retrieved = await meshkit.retrieve(cid);
console.log(new TextDecoder().decode(retrieved)); // hellolocalNode: true starts or attaches to Kubo on http://127.0.0.1:5001 and stores data in ./.ipfs. Add .ipfs to .gitignore.
Your app → init() → Kubo RPC (:5001) → ./.ipfs on disk
upload · retrieve · pin · IPNS
init()— connect to one or more Kubo nodes; optionally spawn a local daemon.meshkit— storage API with failover (upload,retrieve,pin, IPNS).setupGracefulShutdown()— stop a managed Kubo cleanly on Ctrl+C / SIGTERM.
import { readFile } from 'node:fs/promises';
import { init, listPins, setupGracefulShutdown } from '@ipfs-meshkit/meshkit';
const { meshkit, localNode } = await init({ localNode: true });
setupGracefulShutdown(localNode);
const file = await readFile('./document.pdf');
const cid = await meshkit.upload(file);
await meshkit.pin(cid);
const pins = await listPins(meshkit.activeNodes[0]!);
console.log('pinned:', pins.length);Use when Kubo already runs on a server or LAN machine:
import { init } from '@ipfs-meshkit/meshkit';
const { meshkit } = await init({
nodes: ['https://kubo.example.com:5001'],
});
const cid = await meshkit.upload(new Uint8Array([1, 2, 3]));import { init } from '@ipfs-meshkit/meshkit';
const { meshkit } = await init({
localNode: true,
nodes: ['https://backup.example.com:5001'],
});
const backup = new TextEncoder().encode('failover example');
await meshkit.upload(backup);import { init, IPNS_TTL_FAST } from '@ipfs-meshkit/meshkit';
const { meshkit } = await init({ localNode: true });
await meshkit.generateKey('latest');
const contentBytes = new TextEncoder().encode('v1');
const cid = await meshkit.upload(contentBytes);
await meshkit.pin(cid); // publishName does not pin — pin content you care about
const { name } = await meshkit.publishName(cid, {
key: 'latest',
ttl: IPNS_TTL_FAST,
});
const latest = await meshkit.resolveAndRetrieve(`/ipns/${name}`);import { init, setupGracefulShutdown } from '@ipfs-meshkit/meshkit';
const { meshkit, localNode } = await init({ localNode: true });
setupGracefulShutdown(localNode, {
onShutdown: async () => {
// close HTTP server, DB, etc.
},
});import { createMeshkitClient } from '@ipfs-meshkit/meshkit';
const client = createMeshkitClient({ apiUrl: 'http://127.0.0.1:5001' });
const cid = await client.upload(new Uint8Array([1, 2, 3]));const { init } = require('@ipfs-meshkit/meshkit');
(async () => {
const { meshkit } = await init({ nodes: ['http://127.0.0.1:5001'] });
console.log(await meshkit.upload(Buffer.from('hello')));
})();| Export | Purpose |
|---|---|
init() |
Main entry — connect (+ optional localNode) |
meshkit.upload / retrieve / pin |
Storage with failover |
meshkit.publishName / resolveName / resolveAndRetrieve |
IPNS |
meshkit.generateKey / listKeys |
IPNS keystore |
setupGracefulShutdown |
Graceful Kubo shutdown |
listPins |
List pinned CIDs (migration / backups) |
createMeshkitClient |
Single-node RPC client |
startIPFSNode / stopIPFSNode |
Low-level daemon control |
TypeScript types are included (import type { Meshkit, IPFSNodeHandle } from '@ipfs-meshkit/meshkit').
- GitHub Issues — bugs and feature requests
Open source project by IPFS Meshkit Contributors:
- Anurag Pandey — primary development
- Manu Sheel Gupta — project lead
