# cubby

> Simple synchronous JSON storage for Node with TypeScript types.

Latest version **0.2.0** (published 2025-11-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install cubby
pnpm add cubby
yarn add cubby
bun add cubby
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2025-11-06 |
| First published | 2012-11-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 33 |
| Author | Chad Scira |
| Maintainers | icodeforlove |
| Keywords | storage, node, json, typescript |

## Links

- npm: https://www.npmjs.com/package/cubby
- Repository: https://github.com/icodeforlove/node-cubby
- Homepage: https://github.com/icodeforlove/node-cubby#readme
- Issues: https://github.com/icodeforlove/node-cubby/issues
- npm.io page: https://npm.io/package/cubby

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.2.0 (latest) — 2025-11-06
- 0.1.0 — 2019-09-30
- 0.0.3 — 2013-08-24
- 0.0.2 — 2012-11-07
- 0.0.1 — 2012-11-06
- 0.0.0 — 2012-11-06

## README

## cubby

Simple synchronous JSON storage for Node.js, fully typed, no runtime deps.

## Installation

```bash
npm install cubby
```

## API (TypeScript)

```ts
import cubby from 'cubby';

// Arrays
const users = cubby<string[]>('users', []);
users.push('a'); // persists to <projectRoot>/.cubby/users.json

// Objects
const settings = cubby('settings', { theme: 'light' });
settings.theme = 'dark'; // persists
```

Validation with Zod (checked before persisting):

```ts
import { z } from 'zod';
const Tag = z.string();
const tags = cubby('tags', [] as string[], { schema: z.array(Tag) });
tags.push('ok');
// throws and does not persist
// @ts-ignore
tags.push(123);
```

### API

```ts
type ZodLikeSchema<T> = {
  safeParse(input: unknown): { success: true; data: T } | { success: false; error: unknown };
};
function cubby<T>(name: string, defaultValue: T, options?: {
  schema?: ZodLikeSchema<T>;
  dir?: string;
  writeDebounceMs?: number;
}): T;
```

### Storage location

- Defaults to `<projectRoot>/.cubby/<name>.json` where `projectRoot` is the nearest directory containing a `package.json` when starting from `process.cwd()`.
- Override with `dir` if you want a custom directory (tests, ephemeral data, etc.).

### Debounced writes

Provide `writeDebounceMs` to reduce filesystem churn when performing many updates in quick succession.

## Migration from v0.x

No API change for common usage. You can continue using:
```js
const users = cubby('users', []);
users.push('test');
```

## Testing

This project uses Node's built-in test runner.

```bash
npm test
```

---
_Source: https://npm.io/package/cubby · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
