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-config-files

v1.0.0

Published

Simple node module to manage application configuration files

Downloads

4

Readme

node-config-files

While working on any Node project we often face the problem when we need to manage our configuration files based on environments. For instance, most well known environments are development, test and production. And we not limited by them, right!? Projects can have non-standard environment names and for each of them we want sleek and straight forward way of how we manage its configuration files. Here is why node-config-files can come in handy.

Scaffolding

By default node-config-file looks for config folder within the root of our project folder. And, it expects a file structure of this folder to be flat. In other words, node-config-files doesn't support subfolders.

Default

<project_root>/config/*

NOTE: If you prefer to keep our configuration files in different folder, you should specify its path explicitly. See example

File naming

There are rules of how you name your configuration files in order to make them work with node-config-files module.

A file name should follow the pattern: [section].[environment].config.js

Where:

  • section - A property name in a global config object.
  • environment - An environment name in which this configuration will be available.

Here examples of valid configuration file names:

  • project.config.js
  • database.development.config.js
  • rest_api.production.config.js

For files that do not belong to any environment its content will be available over property common in global config object, and for files that do its content available over property env.

Getting started

Install

To install the module run following command in your project folder.

npm i node-config-files --save

Configure

Create a folder where you are going to store configuration files for your applicaiton.

mkdir config

Once folder is created you can start add you configuration files to it.

NOTE: By default this module looks at config folder in the root of your application. But this behaviour can be overridden.

Examples

For more detailed example please see tests

Common use case

/*
	Assume we have following config files
	./config/project.config.js
	./database/database.development.config.js
*/

const config = require('node-config-files')();

config.common.project; // project.config.js
config.env.database;   // database.development.config.js

Custom configuration folder path

const config = require('node-config-files')(
	'./server/config',
	{
	  debug: true,
	  NODE_ENV: 'test'
	}
);

NOTE: Make sure that your path is relative to your project root folder.

Options

  • options.debug - Shows errors in the console, if any. (default: false)
  • options.NODE_ENV - Allows you to override process.env.NODE_ENV. (default: development)

Global config object

This is a common object which will be returned once node-config-files module is invoked.

{
	"common": {},
	"env": {},
	"packageConfig": {}
}

config.common

Contains the content of files which are environment independent.

config.env

Contains the content of files which are environment dependent.

config.packageConfig

Contains properties which were defined in package.json file.

NOTE: Properties dependencies and devDependencies are not included.

Licence

Licensed under GNU GPLv3, see LICENSE for the full license.