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

diamorphosis

v1.0.0

Published

Use - JSON file(s) - .env file for development - ENV vars

Downloads

2,997

Readme

diamorphosis

Use

  • JSON file(s)
  • .env file for development
  • ENV vars

to configure your application for different environments (NODE_ENV). Supports defaults. Supports nested values.

Installation

$ npm install diamorphosis

Features

  • Use JSON or JS files to configure your application for different NODE_ENV values (production, dev, etc...)
// file: config/config.js
{
  my_var_a : "some value",
  myVarB: "some value"
}
// file: config/env/production.json
{
  "nested":{
    "my_var_a" : "some production value",
    "myVarB": "some production value"
  }
}

To enable the production configuration set NODE_ENV=production

  • Overwrite your application's config by using ENV variables and restarting the app. Supports scalar and array values.
export NESTED_MY_VAR_A=someScalarValue
export NESTED_MY_VAR_B=this,var,is,an,array,of,values // NESTED_MYVARB is also supported
export NESTED_BOOLEAN=true
  • Use .env file for development
  NESTED_MY_VAR_A=someValue

Example

// file: config/config.js
// var names should be snakecase (a_var_example) in order to be able to overwrite them correctly using env vars.
module.exports =
{
  varOne: '1_dev_',
  nestedExample: {
    varTwo: '2_dev_'
  }
}
// file: config/evn/production.json
{
  "varOne": '1_prod',
  "nestedExample": {
    "varTwo": "2_prod"
  }
}
// file: config/evn/other.json
{
  "varOne": '1_other',
  "nestedExample": {
    "varTwo": "2_other"
  }
}
// file: app.js
const diamorphosis = require('diamorphosis');
diamorphosis({ // these are the default values
  configFolder: './config',
  configPath: './config/config.js',
  envFolder: './config/env',
  loadDotEnv: ['development'] // will only load .env if NODE_ENV=development
})
// file: myFile.js
const config = require('./config/config');
console.log(var_one:', config.var_one);
console.log(var_two:', config.nested_example.varTwo);

// Env vars can overwrite the config values. The app will need a restart to load the new values:
// export VAR_ONE="some other value for var one"
// export NESTED_EXAMPLE_VAR_TWO="some other value for var two"
# file .env

VAR_ONE=value

Supported types

  • number
  • boolean
  • string

es6 support

Config.js can use the es6 export default eg:

export default {
  varOne: '1_dev_',
  nestedExample: {
    varTwo: '2_dev_'
  }
}

This is especially useful if you are using diamorphosis with typescript.

Note that env files can have .json or .js extension

License

MIT