# @bottender/jfs

> A simple JSON file store

Latest version **0.4.1** (published 2021-11-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @bottender/jfs
pnpm add @bottender/jfs
yarn add @bottender/jfs
bun add @bottender/jfs
```

## Health

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

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

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.1 |
| Published | 2021-11-10 |
| First published | 2021-11-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 4 |
| Unpacked size | 53.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Markus Kohlhase |
| Maintainers | chentsulin, etrexkuo, tw0517tw, link515 |

## Links

- npm: https://www.npmjs.com/package/@bottender/jfs
- Repository: https://github.com/bottenderjs/json-file-store
- Homepage: http://github.com/bottenderjs/json-file-store
- Issues: http://github.com/bottenderjs/json-file-store/issues
- npm.io page: https://npm.io/package/@bottender/jfs

## Dependencies (4)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [async](https://npm.io/package/async.md) ^3.2.1
- [clone](https://npm.io/package/clone.md) ^2.1.2
- [mkdirp](https://npm.io/package/mkdirp.md) ^1.0.4

## Recent versions

- 0.4.1 (latest) — 2021-11-10
- 0.4.0 — 2021-11-10

## README

# JSON file store

A simple JSON file store for node.js.

[![Build Status](https://secure.travis-ci.org/flosse/json-file-store.svg?branch=master)](http://travis-ci.org/flosse/json-file-store)
[![Dependency Status](https://gemnasium.com/flosse/json-file-store.svg)](https://gemnasium.com/flosse/json-file-store)
[![NPM version](https://badge.fury.io/js/jfs.svg)](http://badge.fury.io/js/jfs)
[![License](https://img.shields.io/npm/l/jfs.svg)](https://github.com/flosse/json-file-store/blob/master/LICENCE.txt)

WARNING:
Don't use it if you want to persist a large amount of objects.
Use a real DB instead.

## Install

    npm install jfs --save

## Usage

```javascript
var Store = require("jfs");
var db = new Store("data");

var d = {
  foo: "bar"
};

// save with custom ID
db.save("anId", d, function(err){
  // now the data is stored in the file data/anId.json
});

// save with generated ID
db.save(d, function(err, id){
  // id is a unique ID
});

// save synchronously
var id = db.saveSync("anId", d);

db.get("anId", function(err, obj){
  // obj = { foo: "bar" }
})

// pretty print file content
var prettyDB = new Store("data",{pretty:true});
var id = prettyDB.saveSync({foo:{bar:"baz"}});
// now the file content is formated in this way:
{
  "foo": {
    "bar": "baz"
  }
}
// instead of this:
{"foo":{"bar":"baz"}}

// get synchronously
var obj = db.getSync("anId");

// get all available objects
db.all(function(err, objs){
  // objs is a map: ID => OBJECT
});

// get all synchronously
var objs = db.allSync()

// delete by ID
db.delete("myId", function(err){
  // the file data/myId.json was removed
});

// delete synchronously
db.delete("myId");
```

### Single file DB

If you want to store all objects in a single file,
set the `type` option to `single`:

```javascript
var db = new Store("data",{type:'single'});
```

or point to a JSON file:

```javascript
var db = new Store("./path/to/data.json");
```

### In memory DB

If you don't want to persist your data, you can set `type` to `memory`:

```javascript
var db = new Store("data",{type:'memory'});
```

### ID storage

By default the ID is not stored within your object.
If you like, you can change that behavior by setting `saveId` to `true`
or a custom ID

```javascript
var db = new Store("data",{saveId:'myKey'});
```

### custom ID generator
We use uuid v4 for ID generation if you don't pass an id when save a data. If you want, you can pass custom generator.
```javascript
var i = 0;
var db = new Store("data",{
  idGenerator: function() {
    i = i + 1;
    return i;
  }
});
```


## Tests

    npm test

## License

This project is licensed under the MIT License.

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