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

lambd

v0.2.15

Published

Create & mantain easily Google Cloud Functiosn and/or AWS Lambdas.

Downloads

56

Readme

LAMBD

Create and maintain your AWS Lambdas or Google Cloud Functions functions easily with LAMBD!

How to install

npm i -S lambd

Getting started

How does I select platform?

const Lambd = require('lambd');
const { Platforms } = Lambd;

const myLambdaFunction = ({ request, response }) => {
  // Here your lambda code
  response.json({ ok: true, userid: request.params.userid });
});

// AWS Lambdas by default:
// Lambd.create()

// Google Cloud Functions
// Lambd.createFunctions()

// Otherwise
// You can use Platform enum object and select platform
module.exports.myFunction = Lambd.platform(Platforms.GCLOUD).get('/:userid', myLambdaFunction).getHandler();

// This allows you make compatible all your lambdas between AWS and GCLOUD Functions platforms only you must change platform on code.

Simply example

const Lambd = require('lambd');

const myLambdaFunction = ({ response }) => {
  // Here your functions code
  response.json({ ok: true });
});

module.exports.handler = Lambd.createFunctions().get(myLambdaFunction).getHandler();

### API example

const Lambd = require('lambd');

const myLambda = Lambd.create();

// Middlewares
const authMiddleware = (next) => (options) => {
  const { request, response } = options;
  const { auth } = request;
  if (auth && auth === 'esto_es_una_prueba') {
    next(options);
  } else {
    response.status(403).error('not authorized');
  }
};

const mongoMiddleware = (next) => (options) => {
  const { response } = options;
  const url = 'mongodb://localhost:27017/myproject';
  MongoClient.connect(url, (err, db) => {
    if (err) {
      return response.error(err);
    }
    options.db = db;
    return next(options);
  });
};

myLambda.use(authMiddleware);
myLambda.use(mongoMiddleware);

// Route: /users/:userid
const handler = myLamba
  .get(({ request, db }) => UserService(db).findById(request.params.userid))
  .put('/:userid', ({ request, db }) => UserService(db).findByIdAndUpdate(request.params.userid, request.body))
  .delete(':userid', ({ request, db }) => UserService(db).findByIdAndDelete(request.params.userid))
  .getHandler();

module.exports.handler = handler;

Advanced example

LAMBD allows you use middlewares to add power to your lambda function.

const Lambd = require('lambd');
const { MongoClient } = require('mongodb');

const myLambdaFunction = ({ response, db }) => {
  // Here your lambda code
  db.collection('users').find({}).toArray((err, users) => {
    if (err) {
      return response.error(err);
    }
    return response.json({ ok: true, users });
  });
});

const mongoMiddleware = (next) => (options) => {
  const { response } = options;
  const url = 'mongodb://localhost:27017/myproject';
  MongoClient.connect(url, (err, db) => {
    if (err) {
      return response.error(err);
    }
    options.db = db;
    return next(options);
  });
};

// Global Middleware
// Lambd.use(mongoMiddleware);

// Lambda Middleware
const myLambda = Lambd.create();
myLambda.use(mongoMiddleware);

// Set headers to all lambdas
// Lambd.set('MyFirstHeader', 'value');
// Lambd.set({ 'MySecondHeader': 'value2', 'MyThirdHeader': 'value3' });

// Lambda header
myLambda.set('MyFirstHeader', 'value');
myLambda.set({ 'MySecondHeader': 'value2', 'MyThirdHeader': 'value3' });

module.exports.handler = myLambda.get(myLambdaFunction).getHandler();