🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

middy-env

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

middy-env

Environment variable middleware for the middy framework

2.0.0
latest
Source
npm
Version published
Weekly downloads
946
55.59%
Maintainers
1
Weekly downloads
 
Created
Source

Middy Env

Environment variable middleware for the middy framework

npm version

Install

npm install middy-env

The specified environment variables will be parsed and passed into the handler.

Options

  • cache (boolean) (optional): Set it to true to skip further lookups of environment variables. Defaults to false.
  • cacheExpiryInMillis (int) (optional): Time in milliseconds for values to remain cached. Defaults to undefined.
  • setToContext (boolean) (optional): This will assign the parsed values to the context object of the function handler rather than to process.env. Defaults to true.
  • names (object) (required): Map of environment variables to parse, where the key is the destination.
    Either provide just the environment variable key. Or provide the key, type and fallback value e.g. ['KEY', 'string', 'fallbackValue'].

By default parameters are assigned to the function handler's context object. They can instead be assigned to the Node.js process.env object by setting the setToContext flag to false.
If no fallback value is provided a ReferenceError will be thrown if an environment variable is undefined.

Supported Types

  • string
  • int
  • float
  • bool

Usage

const middy = require('middy');
const env = require('middy-env');

const handler = (event, context, callback) => {
  callback(null, `Hello ${context.firstName} ${context.lastName}`);
};

module.exports = middy(handler)
  .use(env({ 
    names: {
      firstName: ['FIRST_NAME', 'string', 'World'],
      lastName: 'LAST_NAME'
    },
    cache: true,
    cacheExpiryInMillis: 3600000
  }));

Keywords

middy

FAQs

Package last updated on 09 Sep 2021

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