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

tconfig

v0.1.4

Published

A simple transparent config file loader for Nodejs applications. any config field can be overriden using environmen variables

Downloads

5

Readme

tconfig

A simple and transparent config file loader for Nodejs applications.

install

npm i tconfig

Usage

const conig = require('tconfig');

console.log( config ); // your config object

Examples

// file: xyz.js

/*
▾ app/
    ▾ config/
       default.js     // port = 3000
       production.js  // port = 4000
    xyz.js
    package.json
*/


console.log( require('tconfig') );

Simple case

hari@hari-VirtualBox:~app$ node xyz.js 
{ port: 3000 }

Read additional config based on NODE_ENV variable.

If we specify NODE_ENV=xyz then, config/xyz.js will overide the values from default.js. Overriding is a deep merge

hari@hari-VirtualBox:~app$ env NODE_ENV=production node xyz.js 
{ port: 4000 }

Set any configuration variable using Environtment variable.

By setting an Environtment variable '=', we can set config[key] as value.

** First we will try to parse value as json. It it is failed value will be treated as string **

** If a values if parsable as JSON object, then it will be deep merged with default configuration ** Default prefix is TC_ ( Can be changed by setting TC_PREFIXenv variable) For eg:

  • TC_port will set config.port
  • TC_a.b.c will set config.a.b.c
  • TC_a='{"a":{"b":{"c": 123546 }}}' will also set config.a.b.c
  • TC_port=8000 will set { port: 8000 } By default, number will parsed as json number.
  • TC_port='"8000"' will set { port: '8000' } ( now port is a string because double quoted value will be parsed as string in json )
hari@hari-VirtualBox:~app$ env NODE_ENV=production TC_db.mysql.user=root node xyz.js 
{ port: 4000, db: { mysql: { user: 'root' } } }
Use custom env prefix.

default prefix can be changed using Environtment variable by setting TC_PREFIX Environtment variable

export TC_PREFIX=MYAPP_
export MYAPP_port=8080
hari@hari-VirtualBox:~app$ env MYAPP_db.mysql.user=root node xyz.js 
{ port: 8080, db: { mysql: { user: 'root' } } }

use custom config directory

config directory can be changed using Environtment variable by setting CONFIG_DIR Environtment variable

hari@hari-VirtualBox:~app$ env CONFIG_DIR=../config TC_PREFIX=MYAPP_ NODE_ENV=production MYAPP_db.mysql.user=root node xyz.js 
{ dir: '../config', db: { mysql: { user: 'root' } } }

printing debug messages

set DEBUG environment variable to tconfig

export DEBUG=tconfig
# OR
export DEBUG='*'

Config directory search path

  • Directory pointed by CONFIG_DIR environment variable
  • < directory or main script >/config
  • < current working directory >/config