Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including middy-env with all npm packages installed. Try it out:

var middyEnv = require("middy-env")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

middy-env v1.0.0

Environment variable middleware for the middy framework

Middy Env

Environment variable middleware for the middy framework

Build Status Coverage Status npm version


npm install middy-env

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


  • 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


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)
    names: {
      firstName: ['FIRST_NAME', 'string', 'World'],
      lastName: 'LAST_NAME'
    cache: true,
    cacheExpiryInMillis: 3600000
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free