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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@supercharge/hapi-google-cloud-functions

v2.0.0

Published

Run your hapi server in a Google Cloud function

Readme


Introduction

Serverless is becoming popular and widely accepted in the developer community. Going serverless requires a mindset shift. Going serverless requires you to think stateless.

This @supercharge/hapi-google-cloud-functions package let’s you use your hapi.js HTTP server in a Google Cloud function.

This package wraps your hapi server and transforms an incoming request to the cloud function into a hapi-compatible request. This request will be injected into your hapi server and the resulting response transformed back into a cloud-function-compatible format.

It’s basically a “done for you” package to run your hapi server in a serverless function on Google Cloud.

Requirements

hapi v19 (or later) and Node.js v12 (or newer)

This plugin requires hapi v19 (or later) and Node.js v12 or newer.

Compatibility

| Major Release | hapi.js version | Node.js version | | --- | --- | --- | | v2 | >=19 @hapi/hapi | >=12 | | v1 | >=18 hapi | >=8 |

Installation

npm i @supercharge/hapi-google-cloud-functions

Usage

Using @supercharge/hapi-google-cloud-functions is pretty straightforward:

'use strict'

const Hapi = require('@hapi/hapi')
const CloudFunctionHandler = require('@supercharge/hapi-google-cloud-functions')

// this `handler` will be used as a cached instance
// a warm function will reuse the handler for incoming requests
let handler

module.exports.http = async (request, response) => {
  if (!handler) {
     // First, compose your hapi server with all the plugins and dependencies
    server = new Hapi.Server()

    await server.register({
      plugin: require('@hapi/vision')
    })

    // Second, create a handler instance for your server which will
    // transform the Cloud function request into a hapi-compatible
    // request. Then, send the request through your hapi server
    // and transform the response from hapi into a
    // function-compatible response
    handler = CloudFunctionHandler.for(server)
  }

  return handler.proxy(request, response)
}

Deployment Example

There’s a deployment example in the supercharge/playground-google-cloud-functions repository.

We used the Serverless framework to deploy a Supercharge app in the playground-google-cloud-functions repository. The Serverless CLI is sweet because it allows you to deploy your app from a single configuration file.

1. Install the serverless-google-cloudfunctions Package

When deploying with the Serverless CLI, you need to add the serverless-google-cloudfunctions package as a dependency to your project. Install it from NPM:

npm i serverless-google-cloudfunctions

Then, you must add it as a plugin to your serverless.yml file. The next step describes this file in more detail.

2. Deploy to a Google Cloud Function

Deploying to Google Cloud from the Serverless CLI needs a keyfile. Follow these steps in the Serverless docs to set up your Google Cloud credentials and generate a keyfile.

Here’s the sample serverless.yml used to deploy the app:

service: supercharge-gcp-function # do not use the "google" in the name

provider:
  name: google
  runtime: nodejs8
  region: europe-west1
  project: your-gcp-project-name
  credentials: ./path/to/your/gcp-keyfile.json

functions:
  app:
    handler: http
    memorySize: 256 # default is 1024 MB
    events:
      - http: path

plugins:
  - serverless-google-cloudfunctions

3. Deploy

Deploy your project to Google Cloud using the Serverless CLI. Run the following command from your project directory:

sls deploy

The deployment process may take some minutes. When finished, you’ll see a URL to access the deployed function. Enjoy!

Contributing

Do you miss a string function? We very much appreciate your contribution! Please send in a pull request 😊

  1. Create a fork
  2. Create your feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request 🚀

License

MIT © Supercharge


superchargejs.com  ·  GitHub @superchargejs  ·  Twitter @superchargejs