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

co-env

v1.2.0

Published

Simple utility to load configuration data from a directory based on the current environment.

Downloads

5

Readme

co-env

co-env is a simple utility to load configuration data from a directory.

Example:

To install with npm: npm install --save co-env

var configLoader = require('co-env');
var path = require('path');
var config = configLoader(path.join(__dirname, './config'));

console.log(config);

Depending on what is inside of your config director you will get a different output. Imagine the following directory structure:

+-- config
|   +-- env
|   |   +-- development.js
|   |   +-- testing.js
|   |   +-- staging.js
|   |   +-- production.js
|   +-- webserver.js
|   +-- database.js
|   +-- auth.js

You would get a config file that would follow the directory structure:

{
	webserver: { ... },
	database: { ... },
	auth: { ... }
}

Notice that the env directory and the local.js file are ignored. These are special constructs...

env directory

If there is an env directory directly inside of the path that is passed into the config loader the env directory will act as environment specific overrides to your config object. For example, if your NODE_ENV environment variable is set to development then the development.js file inside of your env director will override/add values in your resulting config object.

Example env/development.js
module.exports = {
	webserver: baseUrl: 'http://localhost:3000'
};

The above development.js file would override the baseUrl property in your webserver.js file to be 'http://localhost:3000' but only when you are running under your development environment.

Pro Tip: You can also force a specific environment to be loaded from your code by pasing in the name of that environment as the second parameter of the configLoader function call. For example: var config = configLoader(path.join(__dirname, './config'), 'test'); will force the test environment to be used.

local.js

The local.js file in the root of your config directory acts as an ultimate override for your config object. It will be applied after any defaults and environment specific configs are applied, and override any values that conflict. For example, if you wanted to override your database configurations settings for your specific machine (not every single machine running under a development environment) you could use a local.js file to apply these configuration changes. The local.js file should be added to the .gitignore file.

Example local.js
module.exports = {
	database: {
		client: 'pg',
		connection: {
			host: '127.0.0.1',
			user: 'postgres',
			password: '',
			database: 'appdb',
			charset: 'utf8'
		},
		migrations: {
			tableName: 'migrations'
		},
		directory: './seeds/dev'
	}
};

The above local.js file would override the specified database property in your database.js file.