# keyv-file

> File storage adapter for Keyv, using msgpack to serialize data fast and small.

Latest version **5.3.5** (published 2026-06-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install keyv-file
pnpm add keyv-file
yarn add keyv-file
bun add keyv-file
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 5.3.5 |
| Published | 2026-06-26 |
| First published | 2017-08-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 22.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 81 |
| Author | zaaack |
| Maintainers | zaaack |
| Keywords | keyv, fast, storage, cache, simple |

## Links

- npm: https://www.npmjs.com/package/keyv-file
- Repository: https://github.com/zaaack/keyv-file
- Homepage: https://github.com/zaaack/keyv-file#readme
- Issues: https://github.com/zaaack/keyv-file/issues
- npm.io page: https://npm.io/package/keyv-file

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^1.14.1
- [@keyv/serialize](https://npm.io/package/@keyv/serialize.md) ^1.1.1

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 5.3.5 (latest) — 2026-06-26
- 5.3.4 — 2026-06-14
- 5.3.3 — 2025-11-13
- 5.3.2 — 2025-11-12
- 5.3.1 — 2025-11-01
- 5.3.0 — 2025-11-01
- 5.2.0 — 2025-09-14
- 5.1.5 — 2025-09-14
- 5.1.3 — 2025-07-05
- 5.1.2 — 2025-03-02
- 5.1.1 — 2024-12-16
- 5.1.0 — 2024-12-16
- 5.0.4 — 2024-12-12
- 5.0.3 — 2024-09-03
- 5.0.2 — 2024-08-31
- … 21 more at https://npm.io/package/keyv-file/versions

## README

# keyv-file [<img width="100" align="right" src="https://rawgit.com/lukechilds/keyv/master/media/logo.svg" alt="keyv">](https://github.com/lukechilds/keyv)

> File storage adapter for Keyv, using json to serialize data fast and small.

[![publish](https://github.com/zaaack/keyv-file/actions/workflows/publish.yml/badge.svg)](https://github.com/zaaack/keyv-file/actions/workflows/publish.yml)
[![npm](https://img.shields.io/npm/v/keyv-file.svg)](https://www.npmjs.com/package/keyv-file)

File storage adapter for [Keyv](https://github.com/lukechilds/keyv).

TTL functionality is handled internally by interval scan, don't need to panic about expired data take too much space.

## Install

```shell
npm install --save keyv keyv-file
```

## Usage

### Using with AI agent

```sh
npx skills add https://github.com/zaaack/prompts --skill keyv-file

```

### Using with keyv
```js
const Keyv = require('keyv')
const { KeyvFile } = require('keyv-file')

const keyv = new Keyv({
  store: new KeyvFile()
});
// More options with default value:
const customKeyv = new Keyv({
  store: new KeyvFile({
    filename: `${os.tmpdir()}/keyv-file/default.json`, // the file path to store the data
    expiredCheckDelay: 24 * 3600 * 1000, // ms, check and remove expired data in each ms
    writeDelay: 100, // ms, batch write to disk in a specific duration, enhance write performance.
    encode: JSON.stringify, // serialize function
    decode: JSON.parse // deserialize function
  })
})
```

### Using directly

```ts
import KeyvFile, { makeField } from 'keyv-file'

class Kv extends KeyvFile {
  constructor() {
    super({
      filename: './db.json'
    })
  }
  someField = makeField(this, 'field_key')
}

export const kv = new Kv

kv.someField.get(1) // empty return default value 1
kv.someField.set(2) // set value 2
kv.someField.get() // return saved value 2
kv.someField.delete() // delete field
```

## License

MIT

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