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

@react-foundry/fastify-session

v0.1.7

Published

Fastify plugin to provide a session.

Readme

React Foundry - Fastify Session

Fastify plugin to provide a session in req.session. Supports a few modes of operation:

  1. Custom (hook up to Redis or similar)
  2. In-memory (for testing)
  3. Encrypted cookies (data must be kept small)

Using this package

First install the package into your project:

npm install -S @react-foundry/fastify-session

Then use it in your code as follows:

import Fastify from 'fastify';
import { SessionStore, fastifySession } from '@react-foundry/fastify-session';

const httpd = Fastify();

httpd.register(fastifySession, {
  store: SessionStore.Custom,
  read: (id) => {
    const data = PULL_FROM_STORE(id); // Replace this with something that will pull data out of a store based on the `id`.
    return data;
  },
  write: (id, data) => {
    // Add code to write the session `data` based on the `id`.
  },
  cookies: {
    secret: 'changeme' // Change this to a secret string that is shared across instances of your application
  }
});

httpd.get('/', async (req, reply) => {
  const count = (req.session.count || 0) + 1;

  req.session.count = count;

  return count;
});

await httpd.listen({
  host: '::'
  port: 8080
});

fastifySession

A Fastify plugin which can be 'registered' with the following options.

Options object:

  • store: 'cookies' | 'custom' | 'memory' Default: 'cookies'

    The data store to use for the session. 'cookies' provides a very small session in an encrypted cookie. (Data size is severely limited.) 'memory' stores data in the memory of the instance which works as long as you don't have multiple instances and don't restart the application. 'custom' can be used to provide bespoke read and write functions to pull and push data from a data store of your choice, such as a database.

  • read: function(id: string): object | Promise<object> When using a 'custom' store, this function must be provided to return the session data for the provided session id.

  • write: function(id: string, data: object): void | Promise<void> When using a 'custom' store, this function must be provided to write the provided session data according to the provided id.

  • cookies: object See: https://www.npmjs.com/package/@react-foundry/fastify-consent-cookies

    Make sure that you at least provide a secret.

    • secret: string A secret that is used to encrypt your cookies. You should ensure that you set this in production to ensure that they cannot be decrypted by an attacker. If you horizontally scale your application, you must ensure that the secret is shared between each instance, so that they can decrypt cookies that were set by other instances.

req.session: object

An object representing the session data for the particular request. When you write to this object, it will be persisted in the session and so will also be available on the next request that the user makes.

Working on this package

Before working on this package you must install its dependencies using the following command:

pnpm install

Building

Build the package by compiling the source code.

npm run build

Clean-up

Remove any previously built files.

npm run clean