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

@neo9/n9-node-conf

v2.0.0

Published

Conf node module loader

Downloads

816

Readme

n9-node-conf

Conf node module loader.

npm version Travis Coverage license

Installation

yarn add @neo9/n9-node-conf

or

npm install --save @neo9/n9-node-conf

V2 Upgrade

  • Drop Node.js V 16 support as it has reached end of life
  • Change extendConfig setting from string to object. Example :
{
	...,
	extendConfig: {
		key: 'appName'
	}
}
{
	...,
	extendConfig: {
		key: {
			name: 'appName'
		}
	}
}

Usage

n9NodeConf([options])

Options:

  • path: String, default: process.env.NODE_CONF_PATH || './conf/'

Example:

import n9NodeConf from '@neo9/n9-node-conf';
import { join } from 'path';

const conf = n9NodeConf({
	path: join(__dirname, 'conf'),
});

Options :

N9ConfOptions :

path

Type: string
Required
Path to the folder containing the configuration files. See the structure for more details.

extendConfig

Type: object
Default: undefined To describe extension configuration. Extension configuration ca be a json, yaml or yml file.
In the order, it will try to load the path given, then the same file changing the extension to another supported.

| given | 2nd try | 3rd try | | :---: | :-----: | :-----: | | json | yaml | yml | | yaml | yml | json | | yml | json | yaml |

path

Type: object
Required
To describe where to find extension configuration. One of absolute or relative is required.

absolute

Type: string
Required if relative is not filled
Absolute path to the extension configuration.
Example : Path.join(__dirname, 'conf/env.json')

relative

Type: string
Required if absolute is not filled
Relative path to the conf folder path
Example : './env.json'

key
name

Type: string
Default the app name from package.json.name
The key to use in configuration extension. The path to load the conf will be {env}.{app name}

format

Type: ExtendConfigKeyFormat
Default to undefined.
The format to apply to the packageJSON.name to find the key name. The path to load the conf will be {env}.{format}({app name})

mergeStrategy

Type: N9ConfMergeStrategy (v1 or v2)
Default: v2
The merge strategy to use to merge extension configuration with the other.

  • v1 : Use lodash merge function. Mainly, merge deeper in arrays
    [a, b] + [c, d] → [merge(a, c), merge(b, d)]
  • v2 : Use built in mechanism. It replace array is any
    [a, b] + [c, d] → [c, d]

overridePackageJsonDirPath

Type: string
Default: undefined, use npm module app-root-dir to find package.json Used to load package.json, to find app name, app version and with app name to build the path to load the conf extension.

override

Type: object
Default undefined, no override Override the conf at the end of loading.

value

Type: object
Default: undefined, not applied
Value to override the conf at the end of loading. Merge strategy used is defined bellow. Useful for tests.

mergeStrategy

Type: N9ConfMergeStrategy
Default : N9ConfMergeStrategy.V2
Merge strategy to use to merge override.

Structure

conf/
  application.ts
  development.ts
  integration.ts
  local.ts # should be in .gitignore
  preproduction.ts
  production.ts
  staging.ts
package.json

The module will load these files, every file overwrites the one before:

application.js + ${process.env.NODE_ENV}.js + local.js

  1. If process.env.NODE_ENV is not defined, default to 'development'
  2. If local.js does not exists, it will be ignored.
  3. It will also fetch the package.json of the app to fill its name & version

This module can use a configuration extension, see here for more information.

Example

package.json

{
	"name": "my-app",
	"version": "0.1.2"
}

conf/application.ts

export default {
	http: {
		port: 6686,
	},
};

conf/development.ts

export default {};

conf/production.ts

export default {
	http: {
		port: 80,
	},
};

loadConf.ts

import n9NodeConf from '@neo9/n9-node-conf';

const conf = n9NodeConf();
console.log('const conf =', conf);

node loadConf.ts

const conf = {
	name: 'my-app',
	version: '0.1.2',
	env: 'development',
	http: {
		port: 5000,
	},
};

NODE_ENV=production node loadConf.ts

const conf = {
	name: 'my-app',
	version: '0.1.2',
	env: 'production',
	http: {
		port: 80,
	},
};

Logs

To display the logs of the module, you can use DEBUG=n9-node-conf.