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

deo

v0.0.2

Published

12factor config manager

Downloads

12

Readme

deo

npm version License Build Status

Minimalistic, safe and easy to use 12factor config manager for Node.js

Table of Contents

  1. Installation
  2. Motivation
  3. Usage
  4. Spec
  5. Development
  6. Contributing
  7. License

Installation

$ npm install deo --save

Motivation

The twelve-factor app stores config in environment variables (often shortened to env vars or env). Env vars are easy to change between deploys without changing any code; unlike config files, there is little chance of them being checked into the code repo accidentally; and unlike custom config files, or other config mechanisms such as Java System Properties, they are a language- and OS-agnostic standard.

However, there are a couple of things you must consider before you start referring to process.env all over the place:

  • Spreading the knowledge on where your config values are coming from is not great. Ideally, we want to encapsulate this in a single place.
  • process.env does not guarantee that the given environment variable will exist, you have to do this manually
  • People often end up with .env.example files, documents describing everything that needs to be set so you can run the app etc.
  • Some config values are almost static, they are not sensitive, they do not change in the different environments, however we still refer to them as config. So we end up either putting them inside the env vars or creating a different "special" config objects

deo can will help you deal with those problems and more. Here is how:

  • Safe by design: every specified config entry must be set, otherwise it will throw an exception
  • It makes the entire config immutable, therefore you cannot incidentally reassign a config value. Trying to do so will result in an exception.
  • Encapsulates the knowledge about where your config data is coming from.
  • It comes with a minimalistic API, there is only one function that you can call, therefore it's very easy to stub/mock or replace, if necessary, with an alternative solution

Usage

Here is how you can use it in a simple express app:

config.js:

import deo from 'deo'

export default deo({
  server: {
    hostname: 'producthunt.local',
    port: null // you must set a PORT env variable, otherwise deo will throw
  }
})

app.js:

import express from 'express'
import config from './config'

const app = express()

app.listen(config('server.port'), config('server.hostname'))

Run the app:

$ PORT=4000 node index

deo also works great with envc, dotenv and other .env file loaders:

.env:

PORT=4000

index.js:

import envc from 'envc'

envc() // this will load .env in `process.env`

const config = deo({
  port: 3000
})

console.log(config('port')) // => 4000

Start the app:

$ SECRET=secure node index

You can also provide a custom env object different from process.env:

const customEnv = {
  FOO: 3,
}

const config = deo({
  foo: 0,
}, customEnv)

console.log(config('foo')) // => 3

Development

Setup

$ git clone <this repo>
$ cd deo
$ npm install

Tests

Linters:

$ npm run test:lint

Tests:

$ npm run test:tests

All:

$ npm test

Contributing

Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

 _________________
< The MIT License >
 -----------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||