Skip to content

Libraries

Hypercore

Append-only data log that can be replicated between peers.

Verified 19 October 2026

Record a sequence of events and let another device read the replicated history.

Status in Unstoppable Stack

A log is a storage primitive; your app still defines its records and queries.

How it works

A Hypercore is an ordered log. A writer appends entries and readers address them by zero-based position.

This example stores JSON events locally and reads the latest entry. Restarting with the same directory opens the same log.

Replication exchanges log data; it does not invent an application schema, a query index or a conflict-resolution policy.

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 hypercore-demo
cd hypercore-demo
npm init -y
npm install hypercore@'^11.37.2'

Save as example.mjs:

js
import Hypercore from 'hypercore'
const log = new Hypercore('./data', { valueEncoding: 'json' })
try {
  await log.ready()
  await log.append({ kind: 'note-created', text: 'Hello log' })
  const event = await log.get(log.length - 1)
  console.log(event.text)
  console.log('Entries:', log.length)
} finally {
  await log.close()
}

Run from this example directory:

bash
node example.mjs

Expected result

Hello log Entries: 1 (in a fresh directory; increases on each run)

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

  • ready(): initialize the core before reading properties such as length and key.
  • append(value): add an entry using the configured encoding. get(index) reads an entry.
  • close(): release local resources. For replicated reads, establish replication before waiting for unavailable blocks.

Troubleshooting and limits

  • Entries increase on each run because the example intentionally retains ./data.
  • Use a separate storage directory for each writer process; do not open one directory concurrently.
  • For lookup by record name, use Hyperbee over a core instead of scanning the entire log.

Next steps

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