Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apoyo/config

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apoyo/config

Utils and abstractions focused around configuration

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Apoyo - Config

npm version

Warning: This package is still unstable! The API may still change!

Installation

Install peer dependencies: npm install @apoyo/std

Install package: npm install @apoyo/config

Documentation

The config package series contains utils to facilitate loading your application parameters from different providers (env, aws ssm, gcp secret manager, etc...).

A more complete documentation will be made available once the API has stabilized itself.

Usage

import { getParametersFromEnvironment, Parameters } from '@apoyo/config'
import { getParametersFromSSM } from '@apoyo/config-aws'

async function getParameters(): Parameters {
  const envParams = await getParametersFromEnvironment({
    nodeEnv: process.env.NODE_ENV,
    path: process.cwd()
  })

  const ssmEnabled = envParams['AWS_SSM_ENABLED'] === 'true' ? true : false

  const ssmParams = ssmEnabled
    ? await getParametersFromSSM({
        prefix: envParams['AWS_SSM_PREFIX'],
        key: envParams['AWS_ACCESS_KEY_ID'],
        secret: envParams['AWS_SECRET_ACCESS_KEY'],
        region: envParams['AWS_REGION']
      })
    : {}

  // Merge parameters from env and ssm
  const appParams: Parameters = {
    ...envParams,
    ...ssmParams
  }

  return appParams
}

Once these parameters are loaded, you can use them instead of a hard-coded process.env to configure your services:

import { Parameters } from '@apoyo/config'
import assert from 'assert'

async function configureHttp(parameters: Parameters) {
  // Note: You still need to validate the parameters using the validation library of your choice.

  assert(parameters.PORT, 'The parameter PORT should be defined')

  const port = parseInt(parameters.PORT)

  assert(!isNaN(port) && port > 0, 'The parameter PORT should be a positive integer')

  return {
    port
  }
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

FAQs

Package last updated on 28 Jan 2023

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