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

@scaleway/serverless-functions

v1.1.2

Published

![Tests](https://github.com/scaleway/serverless-functions-node/actions/workflows/tests.yml/badge.svg) ![Examples](https://github.com/scaleway/serverless-functions-node/actions/workflows/examples.yml/badge.svg) [![NPM Version](https://img.shields.io/npm/v/

Downloads

682

Readme

Serverless Functions Node

Tests Examples NPM Version Node

Scaleway Serverless Functions Node is a framework which simplifies working with Scaleway Serverless Functions.

It lets you debug your function locally, emulating the input and output format of a deployed Serverless Function.

Note that this library does not deploy functions for you. For that you can see the available deployment methods.

Some useful links when working with Scaleway Functions:

Testing frameworks for Scaleway Serverless Functions in other languages can be found here:

⚙️ Quickstart

Install this package:

npm i @scaleway/serverless-functions

Add the following in the file where your handle is defined:

For ES Modules

import { pathToFileURL } from "url";

function handle(event, context, callback) {
  return {
    statusCode: 201,
    body: JSON.stringify({
      message: "Hello World!",
    }),
    headers: {
      "Content-Type": "application/json",
    },
  };
}

// This will execute when testing locally, but not when the function is launched
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
  import("@scaleway/serverless-functions").then(scw_fnc_node => {
    scw_fnc_node.serveHandler(handle, 8080);
  });
}

For Common JS

const url = require("url");

module.exports.handle = (event, context, callback) => {
  return {
    statusCode: 201,
    body: JSON.stringify({
      message: "Hello World!",
    }),
    headers: {
      "Content-Type": "application/json",
    },
  };
};

// This will execute when testing locally, but not when the function is launched
if ("file://" + __filename === url.pathToFileURL(process.argv[1]).href) {
  import("@scaleway/serverless-functions").then(scw_fnc_node => {
    scw_fnc_node.serveHandler(exports.handle, 8080);
  });
}

Usage

This file will expose your handler on a local web server, letting you invoke your function code directly.

You can do this as follows:

$ node index.js
$ curl -X GET http://localhost:8080
> Hello World!

By running a function locally like this, we can be sure it will work when deployed to Serverless Functions.

📚 Examples

You can find a number of examples in the examples folder. These include:

🏡 Local testing

What this package does:

  • Formats input: Serverless Functions have a specific input format, wrapping the body of the request with some extra metadata. This package lets you interact with that formatted data.
  • Debugging: It is not possible to remotely debug deployed Serverless Functions. With this package, you can run your functions locally, and debug issues in the emulated environment.

What this package does not do:

  • Simulate performance: Scaleway Functions let you choose different options for CPU/RAM that can have an impact on your function's performance. This package does not emulate these limits. To profile your deployed functions, you can use your Scaleway Cockpit.
  • Deploy functions: Scaleway Functions builds your code before running it. Although this package emulates the runtime environment, it does not emulate the build environment. Therefore it is possible that you may still encounter build issues even if the function passes local tests.

❓ FAQ

Why do I need an additional package to call my function?

The Serverless Functions execution environment wraps your code in an HTTP server, and runs the resulting executable in a Kubernetes cluster behind a load balancer. This introduces a number of layers of abstraction, and additional metadata around the request body. This library attempts to emulate this environment as closely as possible, allowing you to debug your code locally, rather than discovering bugs after deployment.

How my function will be deployed

To deploy your function please refer to the different deployment methods.

Does this package change the runtime behaviour of my function?

No. This package is just for local testing, and will not impact runtime behaviour or performance.

🛟 Help & support

🎓 Contributing

We love to share things with the community. Feel free to raise issues and pull requests on this repo according to the contributing guidelines.

📭 Reach Us

If you want to get in touch with use, you can: