Socket
Socket
Sign inDemoInstall

config-from-schema

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

config-from-schema

A tool for building an application object from config files, command line arguments, or environment variables based on an OpenAPI compatible schema definition.


Version published
Maintainers
1
Created
Source

Config from schema

A tool for building an application object from config files, command line arguments, or environment variables based on an OpenAPI compatible schema definition.

Config schema

Config schema format is defined in the OpenAPI Config Extension Specification.

Features

  • Type coercion
  • Schema validation
  • Command line interface

Usage

  1. Install

    yarn add config-from-schema
    
  2. Create schema

    // schema.js
    const schema = {
      'x-config': [
         {
           name: 'port',
           description: 'Application port',
           default: 3000,
           schema: {
             type: 'integer'
           }
         },
         {
           name: 'secret',
           description: 'Secret used for signing session cookies',
           required: true,
           schema: {
             type: 'string'
           }
         }
      ]
    }
    
    export default schema
    
  3. Build config

    // app.js
    import schema from './schema'
    import configFromSchema from 'config-from-schema'
    
    const config = configFromSchema('foo', schema)
    
    console.info(config.port, config.secret)
    
  4. Run app

    Provide values via CLI args

    $ node app --secret foo
    3000 'foo'
    

    OR via environment variables

    FOO_SECRET=bar node app
    3000 'bar'
    

    OR via a config file

    cat ~/.sso.json | jq .

    $ cat ~/.foo.json
    {
      "secret": "baz"
    }
    $ node app
    3000 'baz'
    
  5. View docs

    $ node app --help
    Usage: app [options]
    
    Options:
      --help    Show help                                                  [boolean]
      --config  Path to config file
                                  [string] [default: "~/.foo.json"]
      --port    Application port                                     [default: 3000]
      --secret  Secret used for signing session cookies          [string] [required]
    

FAQs

Package last updated on 06 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc