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

configuration-by-argument

v1.0.2

Published

Send the path to your JSON configuration file in command line arguments

Downloads

5

Readme

configuration-by-argument

Send the path to your json-file in command arguments. And yes, it's yet another configuration module.

  • Easy and simple to use.
  • Load different configurations based on command arguments.
  • Load multiple configuration files.
  • Validate the config-file using jsonschema

Usage

First install the module:

Use npm to install the module:

	npm install configuration-by-argument

And now for some programming :-)

In the simplest form

Declare a new instance and load the configuration.

	var cba = new configurationByArgument();

	var config = cba.get();

If you have a file named myconfig.json in the root of your directory, and your program is called load-config.js, you can start node like this:

	node load-config --config myconfig.json

File in a sub directory

If your file is not in the root of your application, you can give a relative path to the file as an argument.

	node load-config --config configs/myconfig.json

Double trouble

What if you have more than one configuration file?

Well, you can set the name of the parameter that contains a path to your file.

	node load-config --config1 one.json --configForTesting two.json
	var cba;
	cba1 = new configurationByArgument({ parameterKey: "config1" });

	var config1 = cba.get();

	cba2 = new configurationByArgument({ parameterKey: "configForTesting" });

	var config2 = cba.get();

Options

You can set some options on configuration-by-argument by sending them to the constructor upon initialization.

	var cba = new configurationByArgument({}); //send your options in JSON

validationSchemas

Array of JSON objects OR just a JSON object.

Default: []

Send a schema to validate the config-file against. This is done by jsonschema. See documentation here. When sending an array of schema references, make sure that the base-schema is in position 0.

parameterKey

String.

Default: "config"

The name of the config-parameter. If you want to send paths to more thant one config-file, you have to give the others arguments difference names. See the example near the top for this.

errorHandler

Function.

Override the default error handler by passing your own function in this property.

The default errorhandler looks like this:

	function(ex) {
        throw ex;
    }

Tests

Uses mocha.

To run tests on this module, make sure that the modules for the tests are installed

	npm install configuration-by-argument --dev

Then run:

	npm test

#Futher reading

Further documentation the topics according to this module:

  • jsonschema.
  • Google command line arguments for your environment.

#Keywords

  • configuration
  • config
  • command arguments
  • command line arguments

License

The MIT License (MIT)

Copyright (c) 2016 Thorbjørn Gliese Jelgren (The Right Foot, www.therightfoot.dk)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.