# @siddiqus/app-settings

> A NodeJS utility for storing application settings with in-memory cache access

Latest version **1.0.5** (published 2025-06-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @siddiqus/app-settings
pnpm add @siddiqus/app-settings
yarn add @siddiqus/app-settings
bun add @siddiqus/app-settings
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2025-06-17 |
| First published | 2024-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 67.7 KB |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Sabbir Siddiqui |
| Maintainers | siddiqus |
| Keywords | app-settings, nodejs, database, cache, feature flags |

## Links

- npm: https://www.npmjs.com/package/@siddiqus/app-settings
- Repository: https://github.com/siddiqus/app-settings
- Homepage: https://github.com/siddiqus/app-settings#readme
- Issues: https://github.com/siddiqus/app-settings/issues
- npm.io page: https://npm.io/package/@siddiqus/app-settings

## Dependencies (3)

- [pg](https://npm.io/package/pg.md) 8.11.3
- [mysql2](https://npm.io/package/mysql2.md) 3.6.5
- [mongodb](https://npm.io/package/mongodb.md) 6.3.0

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

- 1.0.5 (latest) — 2025-06-17
- 1.0.4 — 2024-02-06
- 1.0.3 — 2024-02-06
- 1.0.2 — 2024-02-06
- 1.0.1 — 2024-01-24
- 1.0.0 — 2024-01-16

## README

<p align="center">
  <img src="https://cdn-icons-png.flaticon.com/512/6295/6295417.png" width="100" />
</p>
<p align="center">
    <h1 align="center">Node App Settings</h1>
</p>
<p align="center">
    <em>Synchronous data access layer for your app configurations or feature flags as records in your existing database</em>
</p>

## Overview
This package provides an interface for storing data in your existing database with an in-memory cache layer for synchronous data access. The data could be feature flags, application configurations, etc. or anything else that you would need to change on the fly.

Supported databases at the moment are `Postgres`, `MongoDB`, and `MySQL`. The codebase follows a strategy pattern and devs can easily add new database implementations. Feel free to raise a pull request!

## Quick Start

Install as a dependency
```
yarn add @siddiqus/app-settings
```

Example code:

```typescript
import { AppSettings, MongoConfig } from '@siddiqus/app-settings';

// your database config, you can use your own configuration mechanism here
const config: MongoConfig = {
  dialect: 'mongodb',
  host: 'localhost',
  user: 'admin',
  password: 'password',
  database: 'testdb',
}; 

// this can be a singleton in your system
const appSettings = new AppSettings({
  dbConfig: config,
  tableName: 'app_settings_pg',
  refreshIntervalInSeconds: 300 // default interval is 300 seconds (5 minutes)
});

async function run() {
  await appSettings.init(); // this is needed to setup the db tables

  await appSettings.set({
    key: 'hey',
    value: { hey: 'there' },
    type: 'json',
  });

  await appSettings.set({
    key: 'someKey',
    value: 'boop',
    type: 'string', // string | boolean | json | number
  });

  const heyJson = appSettings.get('hey', {}); // notice this does not need await

  console.log(heyJson) // value is the { hey: there } object, or {} by default if the key does not exist 
```

## Internals

### Initialization
On initializing the instance with your database configurations, few things happen:
1. It creates (if not existing) a table to store the settings
2. It will fetch the records from the table and store the formatted data in an in-memory cache

### Fetching Data
- Any time the `set` method is called, it will refresh the cache after the record is added/updated
- A process refreshes the cache every 5 minutes (this is configurable)
- Since the data is coming from in-memory, no need to `await` the `get` or `getAll` functions

<hr/>

### Contributing Guidelines
<details closed>
1. **Fork the Repository**: Start by forking the project repository to your GitHub account.
2. **Clone Locally**: Clone the forked repository to your local machine using a Git client.
   ```sh
   git clone https://github.com/siddiqus/app-settings
   ```
3. **Create a New Branch**: Always work on a new branch, giving it a descriptive name.
   ```sh
   git checkout -b new-feature-x
   ```
4. **Make Your Changes**: Develop and test your changes locally.
5. **Commit Your Changes**: Commit with a clear message describing your updates.
   ```sh
   git commit -m 'Implemented new feature x.'
   ```
6. **Push to GitHub**: Push the changes to your forked repository.
   ```sh
   git push origin new-feature-x
   ```
7. **Submit a Pull Request**: Create a PR against the original project repository. Clearly describe the changes and their motivations.

Once your PR is reviewed and approved, it will be merged into the main branch.

</details>

---

## License

This project is protected under the MIT License. For more details, refer to the [reference](https://opensource.org/license/mit/) website.

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