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

@vercel/fun

v1.1.1

Published

Local Lambda development environment

Downloads

1,710,890

Readme

ƒun

Build Status

Local serverless function λ development runtime.

Example

Given a Lambda function like this one:

// example/index.js
exports.handler = function(event, context, callback) {
	callback(null, { hello: 'world' });
};

You can invoke this function locally using the code below:

import { createFunction } from '@vercel/fun';

async function main() {
	// Starts up the necessary server to be able to invoke the function
	const fn = await createFunction({
		Code: {
			// `ZipFile` works, or an already unzipped directory may be specified
			Directory: __dirname + '/example'
		},
		Handler: 'index.handler',
		Runtime: 'nodejs8.10',
		Environment: {
			Variables: {
				HELLO: 'world'
			}
		},
		MemorySize: 512
	});

	// Invoke the function with a custom payload. A new instance of the function
	// will be initialized if there is not an available one ready to process.
	const res = await fn({ hello: 'world' });

	console.log(res);
	// Prints: { hello: 'world' }

	// Once we are done with the function, destroy it so that the processes are
	// cleaned up, and the API server is shut down (useful for hot-reloading).
	await fn.destroy();
}

main().catch(console.error);

Caveats

ƒun provides an execution environment that closely resembles the real Lambda environment, with some key differences that are documented here:

  • Lambdas processes are ran as your own user, not the sbx_user1051 user.
  • Processes are not sandboxed nor chrooted, so do not rely on hard-coded locations like /var/task, /var/runtime, /opt, etc. Instead, your function code should use the environment variables that represent these locations (namely LAMBDA_TASK_ROOT and LAMBDA_RUNTIME_DIR).
  • Processes are frozen by sending the SIGSTOP signal to the lambda process, and unfrozen by sending the SIGCONT signal, not using the cgroup freezer.
  • Lambdas that compile to native executables (i.e. Go) will need to be compiled for your operating system. So if you are on macOS, then the binary needs to be executable on macOS.

Runtimes

ƒun aims to support all runtimes that AWS Lambda provides. Currently implemented are:

  • nodejs for Node.js Lambda functions using the system node binary
  • nodejs6.10 for Node.js Lambda functions using a downloaded Node v6.10.0 binary
  • nodejs8.10 for Node.js Lambda functions using a downloaded Node v8.10.0 binary
  • nodejs10.x for Node.js Lambda functions using a downloaded Node v10.15.3 binary
  • nodejs12.x for Node.js Lambda functions using a downloaded Node v12.22.7 binary
  • nodejs14.x for Node.js Lambda functions using a downloaded Node v14.18.1 binary
  • python for Python Lambda functions using the system python binary
  • python2.7 for Python Lambda functions using a downloaded Python v2.7.12 binary
  • python3 for Python Lambda functions using the system python3 binary
  • python3.6 for Python Lambda functions using a downloaded Python v3.6.8 binary
  • python3.7 for Python Lambda functions using a downloaded Python v3.7.2 binary
  • go1.x for Lambda functions written in Go - binary must be compiled for your platform
  • provided for custom runtimes