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

no-config

v1.1.2

Published

config and resource loader

Downloads

14

Readme

NPM version Build Status Test Coverage Dependency Status Dependency Status
Intro | Quick start | Quick start (ES6) | API | Contributors | TODO

Intro

Why not config?

Answer. TL;DR: config separates data to different files based on NODE_ENV, not resources.

$ npm install no-config

Quick start

// config.js
module.exports = {
	redis: {
		init: function (params) {
			return require('redis').createClient(params)
		},
		default: {
			db: 0,
			port: 6379
		},
		development: {
			host: '127.0.0.1'
		},
		production: {
			db: 1,
			host: '192.168.0.10'
		}
	}
}
// index.js
require('no-config')({
	config: require('./config')
}).then(
	function(conf) {
		console.log('ENV', conf.env)
		console.log('Redis:', conf.redis.host+':'+conf.redis.port)
		conf.redis.instance.set('hello', 'world')
	}
)
$ NODE_ENV=development node index.js
ENV development
Redis: 127.0.0.1:6379

Quick start (ES6)

Since no-config returns a promise it is much better to use ES6 generators, arrow functions and co.
If you are not familiar with co, check this step-by-step tutorial

// config.js
module.exports = {
	redis: {
		init: params => require('redis').createClient(params),
		default: {
			db: 0,
			port: 6379
		},
		development: {
			host: '127.0.0.1'
		},
		production: {
			db: 1,
			host: '192.168.0.10'
		}
	}
}
// index.js
'use strict'
const co = require('co')
co(function* () {
	let config = require('./config')
	let conf = yield require('no-config')({config})

	console.log('ENV', conf.env)
	console.log('Redis:', conf.redis.host+':'+conf.redis.port)
	conf.redis.instance.set('hello', 'world')
})

API

Loader

require('no-config')(parameters)

Loads resources from parameters.config based on NODE_ENV environment variable. Returns a Promise which resolves ones all resources are initialized.

Parameters

| Name | Required? | Type | Default | Description | | -------------- | --------- | --------------- | ------------- | -------------------------------------------------------- | | config | Required | Object | | Configuration object | | init | Optional | List of strings | All Resources | Resources to initialize | | verbose | Optional | Boolean | false | Print resource input prior to call its init() function | | mask_secrets | Optional | Boolean | true | if verbose === true will hide input value if its key contains substrings: secret, token, key, pass or pwd |

Configuration object

Every high-level key in configuration object is a resource name.

| Name | Required? | Type | Default | Description. Handling | | ------------------- | --------- | ---------- | ------------------ | --------------------------------------------------- | | <RESOURCE> | Optional | Object | | Resource configuration | | <RESOURCE>.defaut | Optional | Object | {} | Default values | | <RESOURCE>.<ENV> | Optional | Object | {} | ENV specific values. If a key duplicates default key, env-specific value is used | | <RESOURCE>.init | Optional | Function, Generator function | | Called to initalize resource, <RESOURCE>.init(result). If returns Promise or Generator, it got resolved with co. Result is saved to result.instance. |

Contributors

Fedor Korshunov - view contributions
Anurag Sharma - view contributions