# config-storage

> Local configuration storage for your applications

Latest version **2.1.3** (published 2023-05-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install config-storage
pnpm add config-storage
yarn add config-storage
bun add config-storage
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.3 |
| Published | 2023-05-26 |
| First published | 2023-04-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 63.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Vicente Gutiérrez |
| Maintainers | vcgtz |
| Keywords | local, storage, storage, config, configuration, json |

## Links

- npm: https://www.npmjs.com/package/config-storage
- Repository: https://github.com/vcgtz/config-storage
- Homepage: https://github.com/vcgtz/config-storage#readme
- Issues: https://github.com/vcgtz/config-storage/issues
- npm.io page: https://npm.io/package/config-storage

## 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

- 2.1.3 (latest) — 2023-05-26
- 2.1.2 — 2023-04-28
- 2.1.1 — 2023-04-28
- 2.1.0 — 2023-04-25
- 2.0.0 — 2023-04-25
- 1.0.0 — 2023-04-24
- 0.0.1 — 2023-04-22

## README

# config-storage
:arrow_down: Package to save your own configuration persistently on your computer.

![npm](https://img.shields.io/npm/l/config-storage?color=blue)
![npm](https://img.shields.io/npm/v/config-storage?color=blue)
[![Node.js CI](https://github.com/vcgtz/config-storage/actions/workflows/node.js.yml/badge.svg?branch=main)](https://github.com/vcgtz/config-storage/actions/workflows/node.js.yml)

## Installation
```bash
npm i config-storage
```

## Usage
### :large_blue_circle: Importing
```js
// using require
const { ConfigurationStorage } = require('config-storage');

// using import
import { ConfigurationStorage } from 'config-storage';
```

### :large_blue_circle: Initialization
#### `ConfigurationStorage.getStorage(storageName: string)`
```js
const config = await ConfigurationStorage.getStorage('my_application');
```

Passing `storageName` allows you to identify your storage with a key. This also means that you can have as many storages as you want.
```js
const mainConfig = await ConfigurationStorage.getStorage('main_configuration');
const userConfig = await ConfigurationStorage.getStorage('user_configuration');
const paymentConfig = await ConfigurationStorage.getStorage('payment_configuration');
```

---
:exclamation: **IMPORTANT**

For all of the following methods that expect a key, you can use **dot-notation** to refer to nested values. For instance, the key `DATABASES.mysql.hostname` refers to an object like:
```js
{
  DATABASES: {
    mysql: {
      hostname: 'localhost'
    }
  }
}
```
---

### :large_blue_circle: Storing values
#### `set(key: string, value: any): Promise<void>`
```js
await config.set('MAIN_KEY', 'GiQTZ8yKBcfuEnTFbs3TvcqoAsF6owLu');
```

### :large_blue_circle: Retrieving values
#### `get(key: string, defaultValue: any = null): Promise<any>`
It returns `defaultValue` if the key doesn't exist.
```js
await config.get('MAIN_KEY');
```

#### `getAll(): Promise<Configuration>`
```js
await config.getAll();
```

### :large_blue_circle: Removing values
#### `del(key: string): Promise<void>`
```js
await config.del('MAIN_KEY');
```

### :large_blue_circle: Checking existence
#### `exists(key: string): Promise<boolean>`
```js
await config.exists('MAIN_KEY');
```

### :large_blue_circle: Cleaning all the stored configuration
#### `clean(): Promise<void>`
```js
await config.clean();
```

## License
[MIT](https://github.com/vcgtz/config-storage/blob/main/LICENSE)

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