🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@odanado/config-loader

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@odanado/config-loader

[![Build Status](https://dev.azure.com/odan3240/config-loader/_apis/build/status/odanado.config-loader?branchName=master)](https://dev.azure.com/odan3240/config-loader/_build/latest?definitionId=1&branchName=master) [![Coverage Status](https://coveralls.i

latest
npmnpm
Version
0.0.6
Version published
Maintainers
1
Created
Source

config-loader

Build Status Coverage Status

Installation

$ yarn add @odanado/config-loader

Usage

In config directory

// config/index.ts
export interface ConfigScheme {
  RDB_USER: string
  RDB_DB_NAME: string
  RDB_PASSWORD: string
}


// config/development.ts
import { MapPlugin, DefinePlugin } from "@odanado/config-loader"
import { ConfigScheme } from "./"

const mapPlugin: MapPlugin<ConfigScheme> = {
  RDB_DB_NAME: new DefinePlugin('test'),
  RDB_PASSWORD: new DefinePlugin('password'),
  RDB_USER: new DefinePlugin('test_user'),
}
export default mapPlugin



// config/production.ts
import { MapPlugin, DefinePlugin, EnvPlugin } from "@odanado/config-loader"
import { ConfigScheme } from "./"

const mapPlugin: MapPlugin<ConfigScheme> = {
  RDB_DB_NAME: new DefinePlugin('test'),
  RDB_PASSWORD: new EnvPlugin('RDB_PASSWORD'),
  RDB_USER: new DefinePlugin('test_user'),
}
export default mapPlugin

In app.ts

import { ConfigLoader } from "@odanado/config-loader"
import { ConfigScheme } from "./config"


async function main() {
  const path = `${process.cwd()}/config`
  const configLoader = new ConfigLoader<ConfigScheme>(path)
  // if NODE_ENV === 'development'
  await configLoader.load() // -> { RDB_DB_NAME: 'test', RDB_PASSWORD: 'password', RDB_USER: 'test_user' }
  
  
  // if NODE_ENV === 'production' and RDB_PASSWORD === 'abcdef'
  await configLoader.load() // -> { RDB_DB_NAME: 'test', RDB_PASSWORD: 'abcdef', RDB_USER: 'test_user' }
}

main()

FAQs

Package last updated on 16 Jul 2019

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