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

dos-config

v3.0.2

Published

Singleton variant of DemocracyOS/config

Downloads

5,115

Readme

DOS Config

Library to configure node apps. At its core uses DemocracyOS/config but with sane defaults.

Keep your default configs on config/defaults.json, override them with config/{NODE_ENV}.json or with environment variables.

Getting Started

1 · Install it: npm install --save dos-config

2 · Run the command: ./node_modules/.bin/dos-config-init. It will create the folder config with the most basic defaults.

3 · Profit 🙌

var config = require('dos-config')

if (config.port) {
  console.log(`The server should run at port ${config.port}. Go code it now.`)
}

Configuring your app

First of all, dos-config will look for the config/defaults.json file, which will define the configuration structure with the default values.

Here's a complete example, keep in mind that the keys of your json files should always be camelCase:

{
  "port": 3000,
  "mongoUrl": "mongodb://localhost/DemocracyOS-dev",
  "staff": [
    "[email protected]",
    "[email protected]"
  ],
  "connectionData": {},
  "auth": {
    "user": "Fring",
    "password": "always-be-secure-123!$"
  }
}
  • The most primitive values are Integer or String. Which work as expected.
  • Array values can only have Strings inside.
  • The empty object {} means that it doesn't have a default value, but can be overriden by absolutely any JSON.

After defining your defaults, you can override them using another json file on your current environment. For example, if you are on your development machine, create config/development.json and add there only the values you want to change (always remember to .gitignore this file!):

{
  "port": 8888,
  "connectionData": {
    "domain": "localhost",
    "port": 27099,
    "user": "root"
  }
}

Excellent! Now you only need to configure your production server.

You have two options; first, do the same as development, but create the file config/production.json on your server, and make sure the NODE_ENV environment variable is set to production.

The other and recommended option for production, is to use environment variables. Here's an example of all the variables you should set to override the previous example:

PORT=8080
MONGO_URL='mongodb://user:pass@mongoserver/DemocracyOS-production'
[email protected],[email protected]
CONNECTION_DATA='{"domain": "127.123.123.123", "port": 3412}'
AUTH_USER='Admin'
AUTH_PASSWORD='some-production-password'
  • All the keys are transformed from camelCase to CONSTANT_CASE.
  • Nested values, just add a _, for example from auth.user as AUTH_USER.
  • Arrays should be divided by commas ,
  • And JSON values are a JSON string.

DOS Config Options

You can only configure the default location of your config folder setting the environment variable CONFIG_PATH, e.g: CONFIG_PATH=/usr/src/config. On that folder it will look for the defaults.json and optionally for the {NODE_ENV}.json.

If you want something more flexible, just use https://github.com/DemocracyOS/config

License