npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@siddiqus/app-settings

v1.0.4

Published

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

Downloads

9

Readme

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:

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

Contributing Guidelines

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


License

This project is protected under the MIT License. For more details, refer to the reference website.