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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sp-conf

v2.2.9

Published

A small framework for reading config

Downloads

86

Readme

SP Conf

Build Status js-standard-style

SimPle CONFig

A small component for reading config. It will log all the variables your are reading so you can see what values your app it using. It will also check where any variables are missing and allow your to respond.

Gettings Started

$ npm install sp-conf --save

How to use

Check out example.js that shows an example of using it.

const conf = require('sp-conf')

const regexForIpV4Address = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/

const myconfig = {
  port: conf.readNumber('PORT', {defaultValue: 8080}),
  user: conf.readString(['CURRENT_USER', 'DEFAULT_USER']),
  serviceUrl: conf.readUrl('SERVICE_URL'),
  database: {
    host: conf.readString('DB_HOST_IP', {validator: regexForIpV4Address}),
    port: conf.readNumber('DB_PORT'),
    username: conf.readString('DB_USERNAME'),
    password: conf.readPassword('DB_PASSWORD'),
    keepConnectionOpen: conf.readBool('KEEP_CONNECTION_OPEN'),
  }
}

conf.makeClonableAndDeepFreeze(myconfig)

if (conf.missingEnvVars) {
  console.error('Some required env vars were missing. Terminating')
  process.exit(1)
}

const mockConfig = conf.cloneAndRefreeze(x => x.user = 'test_user')

// mockConfig would be frozan and mockConfig.user would contain 'test_user'
console.log(mockConfig.user)

module.exports = myconfig

Options common to all methods

  • defaultValue - The value to use if the specified value is not available

  • validator - A regular expressing to specify the format of the input value

  • log - A function that logs about reading env var. Defaults to logging to stdout. E.g. To log messages with a prefix:

log: msg => console.log('message:', msg)
  • error - A function that reports errors while reading env var. Defaults to logging to stderr. E.g. To log errors with a prefix:
error: err => console.error('error:', err)
  • source - The object to read env vars from. Defaults to process.env

Global options

You can set global options by creating an instance rather than using the default object and passing them in.

E.g. To supress all logging:

const conf = require('sp-conf')({
  log: () => {}
})

Methods available

  • readNumber - Read a number and complain if its not a number

  • readString - Read a string not applying any special rules

  • readPassword - Read a string but will obfuscate when logging the value out

  • readUrl - Read a URL and will obfuscate the password if the URL contains one.

  • readBool - Read a boolean and complain if it's not valid. Epected characters are:

    • truthy values - "true", "t", "on", "1"
    • falsy falues - "false", "f", "off", "0" It is not case sensitive so, for example, both "True" and "TRUE" work just fine

Deep freeze

deepFreezeAndMakeClonable This will freeze all the properties on your object as well as sub objects. It will also add a cloneAndRefreeze property to the object that, when called, will create a clone. The clone will also be frozen.

If you want to mutate the clone, when calling cloneAndRefreeze pass a callback with an argument that gets access to the clone before it is frozen.