Giter VIP home page Giter VIP logo

config's Introduction

snyk-config

Loads the configuration for your module.

Usage

Although you can require this module directly, it's recommended you create your own config.ts file that can be cached by the require system and called without a path:

// config.ts
import { loadConfig } from 'snyk-config';
export const config = loadConfig('<directory with config files>');

// in app.ts
import { config } from './config';

// in foo.ts
import { config } from './config'; // matches config in app.ts

Method

The config loader will look for the following values in order of priority, specifically, if a property appears in multiple layers of config (below) the first found is used:

  • process environment values prefixed with SNYK_
  • process arguments
  • a config.secret.json file in the path specified by:
    • the secretConfig option, or
    • the environment variable CONFIG_SECRET_FILE, or
    • in the specified config directory
  • a config.${SERVICE_ENV}.json file in the specified config directory,
    • where SERVICE_ENV defaults to local, if not set
  • a config.default.json file in the specified config directory

Example

config.local.json

{
  "from": "file"
}

app.js

import { loadConfig } from 'snyk-config';
// as we're in the same directory as the config.local.json, there's no arg
const config = loadConfig();
console.log(config);

cli

$ SNYK_from=cli node app.js
=> { from: "cli" }

Notes

  • Values read from the environment or from the process arguments will always be strings or booleans. This is important to differentiate from values parsed in the config files as these can be numbers.
  • Environment property names strip off the preceding SNYK_ string, so SNYK_foo = 10 becomes foo = "10"
  • To create a nested object structure from the environment values, use two underscores: SNYK_foo__bar = 10 becomes foo = { bar: "10" }

config's People

Contributors

remy avatar fauxfaux avatar adrukh avatar jackub avatar robcresswell avatar edwardgeorge avatar gjvis avatar guypod avatar dotkas avatar pavel-snyk avatar shaninja avatar darscan avatar ilantsnyk avatar lili2311 avatar mladkau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.