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

serverless-express

v2.0.12

Published

Run express apps on AWS λ easily.

Downloads

12,634

Readme

:package: :sparkles: Serverless Express Plugin

serverless npm version Coverage Status GitHub license

Make express apps compatible with serverless framework. Ensure compatibility with serverless-offline plugin.

Works with provider :

  • [x] Amazon Web Service - Lambda
  • [x] Google Cloud Platform - Cloud functions
  • [x] Microsoft Azure - Cloud functions

Download

Type this command inside your terminal

npm install --save serverless-express

or for yarn users

yarn add serverless-express

Installation

1 - Add it to your serverless.yml

inside your project's serverless.yml file add serverless-express to the plugin list inside serverless.yml

It should look something like this:

plugins:
  - serverless-foo # <- fake name
  - serverless-express # <- like so

NB: In order to automatically know on which provider the function is executed, the plugin asks serverless to set SERVERLESS_EXPRESS_PLATFORM as an environment variable. The plugin uses it internally

2 - Use serverless-express/express

In the head of your express app file :

  • Replace require('express') by require('serverless-express/express')
  • Make you app exportable

it should look like this:

// const express = require('express');
const express = require('serverless-express/express')
var app = express();


// Q: What is serverless-express/express ??
//
// A: It's express, the exact same express that you already use.
//    We wrapped it and we abstracted away all specific implementation 
//    that has to be done in order to work properly on every provider.
//
//    Basicaly, we just made express development provider agnostic
//    so you can develop your app without any vendor lock-in, yeah !


// --- example code ---
//
// app.get('/some_url', doSomething() )
// app.post('/other_url', doSomethingElse() )
//
// ------- end --------

module.exports = app
// app.listen(PORT, ()=>{
//   console.log('listening')  
// })

3 - In your handler file

inside the handler file, you have to import serverless-express/handler and call it with your express app. It should look something like this:


const handler = require('serverless-express/handler')
const app = require('path/to/your/express/app')

module.exports.api = handler(app)
// that's it ;)

4 - Finished !

Now that everything is done, you can get back to work and enjoy serverless and express in the same time ;)

Usage

Make sure that you register an HTTP event for each endpoint of your express app. For example, if you register an endpoint like this one:

  app.get( '/users' , showUsers )

You will need to make sure that your cloud provider routes the HTTP call to your app. In order to do so, you will need to update your serverless.yml like so :

# like this 
functions:
  app: 
    handler: handler.handler  #assuming your handler file is handler.js
    events: 
      - http:
          method: GET
          path: /users

# or like this
# be careful, this will route every HTTP event to your function.
functions:
  app:
    handler: handler.handler 
    events: 
      - http:
          method: ANY   
          path: /{proxy+}

Todo

  • [ ] create "serverless express yaml" command that updates the serverless.yml file with all the endpoints of the express app