# kv

> an append oriented kv store for streams

Latest version **1.1.1** (published 2013-03-14) · 0 weekly downloads

## Install

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

Provides the command `kv`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2013-03-14 |
| First published | 2012-05-20 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 36 |
| Author | Dominic Tarr |
| Maintainers | dominictarr |

## Links

- npm: https://www.npmjs.com/package/kv
- Repository: https://github.com/dominictarr/kv
- Homepage: http://github.com/dominictarr/kv
- npm.io page: https://npm.io/package/kv

## Dependencies (5)

- [mkdirp](https://npm.io/package/mkdirp.md) ~0.3.4
- [kv-redis](https://npm.io/package/kv-redis.md) ~0.1.0
- [optimist](https://npm.io/package/optimist.md) ~0.3.4
- [event-stream](https://npm.io/package/event-stream.md) ~3.0.7
- [monotonic-timestamp](https://npm.io/package/monotonic-timestamp.md) ~0.0.7

## Recent versions

- 1.1.1 (latest) — 2013-03-14
- 1.1.0 — 2012-12-17
- 1.0.8 — 2012-12-16
- 1.0.7 — 2012-11-29
- 1.0.6 — 2012-11-13
- 1.0.5 — 2012-11-02
- 1.0.4 — 2012-11-01
- 1.0.3 — 2012-10-30
- 1.0.2 — 2012-10-25
- 1.0.1 — 2012-10-25
- 1.0.0 — 2012-10-24
- 0.5.8 — 2012-08-15
- 0.5.7 — 2012-06-13
- 0.5.6 — 2012-06-13
- 0.5.5 — 2012-06-13
- … 12 more at https://npm.io/package/kv/versions

## README

# kv-stream

super simple key-value store, intended for keeping appendable files.

works on the server, with files or redis _and in the browser_ with `localStorage`.

on the server, it keeps the files in prefixed subdirectories, so that the directories do not get too large.

(see ls .git/objects/\* for a similar example)

## examples

###create an instance

`kv(path/prefix/connectString, setup)`

`path` is where to create/connect to the store.

`setup` is optional. `setup` is passed the stream created by `put` and `get`, may replace the stream passed to put/get
by default, the stream is handled as newline seperated json.

```
//files
var kv = require('kv')('/tmp/kv')
//redis
var kv = require('kv/redis')('redis://password@localhost:6379/prefix')
//client
var kv = require('kv')('kv:') //this will be prefixed to keys when saving in localStorage.
```


### put a stream

`opts` is optional. see [fs.createWriteStream](http://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options)

``` js
stream.pipe(kv.put(key, opts))
```

`kv.createWriteStream` is a synonym for `kv.put`

### get a stream

`opts` is optional. see [fs.createReadStream](http://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options)

``` js
kv.get(key, opts).pipe(stream) 
```
`kv.createReadStream` is a synonym for `kv.get`

### del a stream

``` js
kv.del(key, callback)
```

### list of keys

``` js
kv.list().pipe(stream)

```

### has

check if db has a key

``` js
  kv.has(key, function (err, stat) {
    //return the stat of the stream, if it exists.
  })

```

### customization

to handle other types of streams than newline separated json, pass in a stream setup function to kv.

``` js
var rawKV = require('kv')(dir, function (stream, key) {
  return stream //just use raw streams, do not parse!
})
```

# cli

there is also a cli tool!

```
npm install kv -g

echo hello | kv put hello --base /tmp/kv
kv get hello --base /tmp/k

```

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