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

node-env-configs

v1.1.2

Published

Loads configs based on your environment

Downloads

5

Readme

node-env-configs    Build Status

NPM

Loads configuration files based on the NODE_ENV.

Installation

npm i node-env-configs --save

Simple Usage

Run the following commands at the root of your project

Adding default config file.

node-env-configs by default consumes this file and export the content as the default config when NODE_ENV is not set.

$ mkdir configs
$ vim configs/default.js  # or vim config/default.json
// default.js

module.exports = {
  protocol: 'http://',
  host: 'localhost',
  port: 8090,
}
Adding production config file.

node-env-configs will consume production.js and do a shallow merge over the default config.

$ vim configs/production.js
// production.js

module.exports = {
  port: 8000
}
Using in your module

Now, create main.js and add the following code.

  // ES5 way
  const config = require('node-env-configs').default
  console.log(config.port)

  // ES6 way
  import { port } from 'node-env-configs'
  console.log(port)
Making it work

By default, when you run main.js, node-env-configs will check for NODE_ENV and look for the filename matching the NODE_ENV. If NODE_ENV is undefined it will pick default.js | default.json from the root/configs/ and return it as the default config. So, here

$ node main.js
> 8090 #logs 'port' from the 'default.js'

If your set the NODE_ENV=production,

$ NODE_ENV=production node main.js
> 8000 #logs 'port' from the 'production.js'

Environment Variables

ENV_CONFIGS_DIR

Description: This specifies node-env-configs where the config files are saved in the project.

Default: <projectRoot>/configs/

Usage:

$ ENV_CONFIGS_DIR=app/configs node main.js # now node-env-configs will look for configs from the specified path
SUPPRESS_ENV_CONFIGS_WARNINGS

Description: This specifies node-env-configs to do or do not show warnings and errors on the console.

Default: false

Usage:

$ SUPPRESS_ENV_CONFIGS_WARNINGS=true node main.js # this will suppress all the warnings and the errors

Supported File Formats

node-env-configs supports the following file formats

  • .js
  • .json

You can have both the formats in the same project or the config directory.

License

The MIT License (MIT)

Copyright (c) 2016 Pranesh Ravi