Skip to content

Libraries

Corestore

Manages a collection of Hypercores and their storage lifecycle.

Verified 19 October 2026

Open named cores for settings and notes, then replicate the application's store through a peer connection.

Status in Unstoppable Stack

Keep the store in the worker and close it when the application shuts down.

How it works

Corestore manages multiple Hypercores under one storage root. Names let an application reopen the same local cores without manually tracking each key.

The example separates note data from an activity log. The first note stays the same while the activity count grows on each run.

A shared store can supply cores for a database or file drive. The owner of the store also owns its lifetime.

Run an example

Use Node 22.17+ and npm for installation. Start in a new directory for this example so its ./data storage cannot collide with another example. Save each file below with the exact filename shown, then run the commands in order.

bash
mkdir corestore-demo
cd corestore-demo
npm init -y
npm install corestore@'^7.13.0'

Save as example.mjs:

js
import Corestore from 'corestore'
const store = new Corestore('./data')
try {
  const notes = store.get({ name: 'notes', valueEncoding: 'json' })
  const events = store.get({ name: 'events', valueEncoding: 'json' })
  await Promise.all([notes.ready(), events.ready()])
  if (notes.length === 0) await notes.append({ text: 'My first note' })
  await events.append({ kind: 'opened' })
  console.log((await notes.get(0)).text)
  console.log('Open events:', events.length)
} finally {
  await store.close()
}

Run from this example directory:

bash
node example.mjs

Expected result

My first note Open events: 1 (increases when you run it again)

Example verification

The code shown here ran successfully in a local check on 19 October 2026. This verifies the small example, not production readiness, public-network reachability or every platform.

API essentials

  • get({ name, valueEncoding }): open or create a named core. Await that core's ready() before inspecting its metadata.
  • replicate(connection): attach replication to a peer stream; connect before requesting missing remote data.
  • close(): close the store after consumers have finished. Child sessions and separately owned resources need their own cleanup.

Troubleshooting and limits

  • A changed storage directory creates a different store and identity; use a stable app-owned path.
  • Names are local identifiers. Peers need the appropriate public dataset keys to open replicated data.
  • Do not replicate sensitive cores merely because another peer is connected; define which resources the app shares.

Next steps

Need help? Report an issue with your CLI version, platform, command and first relevant error.