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-stack/node

v1.18.4

Published

The `@serverless-stack/node` package provides helper libraries used inside the Lambda function code.

Downloads

2,103

Readme

@serverless-stack/node npm

The @serverless-stack/node package provides helper libraries used inside the Lambda function code.

View the @serverless-stack/node docs here.

Installation

# With npm
npm install @serverless-stack/node
# Or with Yarn
yarn add @serverless-stack/node

Exports

The @serverless-stack/node package is made up of a collection of modules. Like the @serverless-stack/node/api, @serverless-stack/node/bucket, etc. Each of these modules has 3 types of exports:

Properties

The properties in each module helps you access the resources that are bound to the function.

// Create an S3 bucket
const bucket = new Bucket(stack, "myFiles");

new Function(stack, "myFunction", {
  handler: "lambda.handler",
  // Bind to function
  bind: [bucket],
});

You can access the bucket name in your function by importing Bucket from the @serverless-stack/node/bucket module:

import { Bucket } from "@serverless-stack/node/bucket";

console.log(Bucket.myFiles.bucketName);

Due to the use of top-level await, your functions need to be bundled in the esm format.

Handlers

The handlers in each module is a function that can wrap around Lambda function handlers.

import { ApiHandler } from "@serverless-stack/node/api";

export const handler = ApiHandler((event) => {
  // ...
});

Each handler has a specific purpose but they share a couple of things in common:

  1. Provide proper typesafety.
  2. They also initialize SST's context system to power our Hooks.

Hooks

The hooks in each module are functions that you can call anywhere in your application code. It has access to things that are specific to the current invocation. This avoids having to pass things through multiple function calls down to our domain code.

import { useSession } from "@serverless-stack/node/auth";

const session = useSession();

if (session.type === "user) {
  console.log(session.properties.userID);
}

Behind the scenes, Hooks are powered by a SST's context system.

Others

Some of the modules also export types that can be used to define payloads for function calls. They also optionally export methods.

Usage in tests

To access the properties in your tests, you'll need to wrap your tests with the sst bind CLI.

sst bind -- vitest run

This allows the @serverless-stack/node package to work as if it was running inside a Lambda function.