0.0.4 • Published 4 years ago

mookie v0.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Node.js middleware engine for AWS Lambda using async functions.

Installation

npm install mookie

Usage

const mookie = require('mookie')

function debug(v) {
  console.log(JSON.stringify(v, null, 2), '\n')
}

async function error(handler, next) {
  try {
    await next()
  } catch (err) {
    console.log(err.message)
  }
}

async function inputOutputLogger(handler, next) {
  debug({ event: handler.event })
  await next()
  debug({ response: handler.response })
}

async function myLambdaFunction(event, context) {
  return {
    event,
    context,
    message: 'Hello world!'
  }
}

exports.handler = mookie(myLambdaFunction)
  .use(error)
  .use(inputOutputLogger)