npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lambda-expressless

v1.7.2

Published

Wrap AWS Lambda functions with Express-like functions to simplify your code

Downloads

17

Readme

lambda-expressless

Build Status npm version codecov semantic-release

Wrap AWS Lambda functions with Express-like functions to simplify your code

So instead of writing this:

exports.handler = (event, context, callback) => {
  const requestBody = JSON.parse(event.body);
  const responseBody = {
    success: false,
    data: requestBody.id
  };

  callback(null, {
    statusCode: 201,
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(responseBody)
  });
}

you'll have this:

const { use } = require('lambda-expressless');
const bodyParser = require('body-parser');

exports.handler = use(bodyParser.json(), (req, res) => {
  res.status(201).json({
    success: false,
    data: req.body.id
  })
});

You can also use multiple middlewares for a single handler:

const { use } = require('lambda-expressless');

const checkUser = (req, res, next) => {
  if (req.get('Authorization') === 'someToken') {
    next()
  } else {
    req.status(403).end('Forbidden');
  }
};

const getUser = (req, res) => {
  res.json({
    id: '12',
    name: 'Murat'
  });
};

exports.handler = use(checkUser, getUser);

TypeScript example:

import { use, Request, Response } from 'lambda-expressless';
import * as bodyParser from "body-parser";

const addUser = (req: Request, res: Response, next: Function) => {
  UserService.add(req.body);

  // add user
  res.json({success: true});
};

export const handler = use(
  bodyParser.json(),
  addUser
);

You can use many popular Express Middlewares. Some tested examples are:

Installation

npm i lambda-expressless

Supported Features and Limitations

This project aims to implement functionalities of ExpressJS middlewares as much as possible. Request and Response objects have properties and methods listed below.

Request Object

Properties:

| Property | Notes | |-------------|-------| | body | You need to use body-parser | | hostname | - | | host | - | | xhr | - | | ip | - | | ips | - | | path | - | | protocol | - | | secure | - | | method | - | | query | - | | params | - | | headers | - |

Methods:

| Method | Notes | |-------------|-------| | accepts() | - | | acceptsEncodings() | - | | acceptsCharsets() | - | | acceptsLanguages() | - | | get() | - | | header() | - | | is() | - |

Response Object

Methods:

| Method | Notes | |-------------|-------| | get() | - | | format() | Doesn't support shorthand mime-types | | set() | Only supports key, value parameters | | send() | Only supports string values | | status() | - | | end() | - | | json() | - | | type() | - |

Contribution

Every contribution is very welcome. Keep these in your mind when you want to make a contribution:

  1. Because of we use semantic-release you need to use Angular Commit Message Conventions in your commit messages.
  2. Keep code coverage 100% with your updated tests.
  3. Check your changes with a Lambda environment. You can use SAM-CLI to test on your local.
  4. Don't forget to update documentation(this readme file) about your changes.