Node.js quickstart

This is a ~60-second round-trip: snapshot a directory, push it to a local file:// store, pull it back into a fresh directory, and confirm the snapshot ID matches. Snapshot IDs are 64-character lowercase hex and are bit-identical to the CLI and every other binding.

1. Install

npm install @snapdir/snapdir

Prebuilt native binaries, no compiler required. See Install snapdir for Node.js for platform details.

2. Snapshot + push

Compute the snapshot ID for a directory, then push it to a local store. Both calls return the same 64-character lowercase hex ID.

import { id, push } from '@snapdir/snapdir'

const store = `file://${process.cwd()}/store`

// Snapshot ID without touching a store — pure, deterministic.
const snapshotId = await id('./my-dir')
console.log(snapshotId) // 64-char lowercase hex

// Upload the snapshot to the store; returns the same ID.
const pushed = await push('./my-dir', store)
console.log(pushed === snapshotId) // true

3. Pull it back

Materialize the snapshot into a fresh directory and re-derive its ID — it is the same string you started with.

import { id, pull } from '@snapdir/snapdir'

const store = `file://${process.cwd()}/store`

await pull(snapshotId, store, './restored')

const restoredId = await id('./restored')
console.log(restoredId === snapshotId) // true

That <snapshot-id> is the exact same value you would get from snapdir id or snapdir push on the CLI — the binding wraps the identical Rust core.