# json-datastore

> File-based JSON datastore

Latest version **0.3.0** (published 2018-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-datastore
pnpm add json-datastore
yarn add json-datastore
bun add json-datastore
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2018-08-09 |
| First published | 2016-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 12.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Steve Randy Tantra |
| Maintainers | steverandy |
| Keywords | file, json, store, datastore |

## Links

- npm: https://www.npmjs.com/package/json-datastore
- Repository: https://github.com/steverandy/json-datastore
- Issues: https://github.com/steverandy/json-datastore/issues
- npm.io page: https://npm.io/package/json-datastore

## Dependencies (3)

- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [util.promisify](https://npm.io/package/util.promisify.md) ^1.0.0
- [write-file-atomic](https://npm.io/package/write-file-atomic.md) ^2.3.0

## 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.3.0 (latest) — 2018-08-09
- 0.2.0 — 2018-08-06
- 0.1.7 — 2018-07-19
- 0.1.6 — 2016-09-08
- 0.1.5 — 2016-09-07
- 0.1.4 — 2016-09-04
- 0.1.3 — 2016-09-04
- 0.1.2 — 2016-09-04
- 0.1.1 — 2016-09-04
- 0.1.0 — 2016-09-04

## README

# json-datastore

File-based JSON datastore.

## Install

```
$ npm install --save json-datastore
```

## Usage

``` javascript
let datastore = require("json-datastore")

// Write to a datastore
datastore.write("/path/to/datastore", {
  _id: "global-config", checkUpdates: false
}).then(doNextThing)

// Write to users collection
datastore.write("/path/to/datastore/users", {
  _id: 1, name: "Steve"
}).then(doNextThing)

// Read by id in users collection
datastore.read("/path/to/datastore/users", {_id: 1}).then(user => {
  doNextThing(user)
})

// Read all in users collection
datastore.read("/path/to/datastore/users").then(users => {
  doNextThing(users)
})

// Read all in users collection in descending order
datastore.read("/path/to/datastore/users", {}, {
  descending: true
}).then(users => {
  doNextThing(users)
})

// Remove all in users collection
datastore.remove("/path/to/datastore/users").then(doNextThing)
```

## API

**datastore.read(path, query, options)**<br>
Read one or many documents in the specified path.

**datastore.write(path, object, options)**<br>
Write object to a JSON file in the specified path. An `_id` is generated by default for the object and used as the file name. You can partition the store by writing to sub-directories.

**datastore.remove(path, query)**<br>
Remove one or many documents in the specified path.

## License

[MIT License](./LICENSE)

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