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

@scratchyjs/renderer

v26.3.22-1774223623833

Published

Worker-thread SSR and SSG for the Scratchy framework. Manages a [Piscina](https://github.com/piscinajs/piscina) worker pool for server-side rendering, exposes a Fastify plugin, an SSR route handler factory, an SSG pipeline, and low-level SharedArrayBuffer

Downloads

280

Readme

@scratchyjs/renderer

Worker-thread SSR and SSG for the Scratchy framework. Manages a Piscina worker pool for server-side rendering, exposes a Fastify plugin, an SSR route handler factory, an SSG pipeline, and low-level SharedArrayBuffer / Redis communication helpers for main-thread ↔ worker data exchange.

Installation

pnpm add @scratchyjs/renderer

Usage

Register the worker-pool plugin

import rendererPlugin from "@scratchyjs/renderer/plugin";
import { resolve } from "node:path";

await server.register(rendererPlugin, {
  worker: resolve(import.meta.dirname, "worker.js"),
  minThreads: 2,
  maxThreads: 8,
  taskTimeout: 30_000,
});

// Now available:
//   server.piscina   — the Piscina pool
//   server.runTask() — dispatch a render task

SSR route handler

import { createSSRHandler } from "@scratchyjs/renderer";

fastify.get(
  "/*",
  createSSRHandler({
    getProps: (request) => ({ user: request.user }),
  }),
);

SSG pipeline

import { runSsgPipeline } from "@scratchyjs/renderer";

const results = await runSsgPipeline({
  routes: ["/", "/about", "/blog"],
  runTask: server.runTask,
  outputDir: "./dist",
});

SharedArrayBuffer communication (zero-copy)

import {
  BufferStatus,
  createSharedBuffer,
  readFromBuffer,
  writeToBuffer,
} from "@scratchyjs/renderer";

// Main thread — create and write
const shared = createSharedBuffer(64 * 1024); // 64 KB payload area
writeToBuffer(shared, { route: "/about", user: null });

// Worker thread — read
const data = readFromBuffer<{ route: string }>(shared);

Redis communication (distributed)

import {
  cleanupRenderContext,
  getRenderContext,
  storeRenderContext,
  storeRenderResult,
} from "@scratchyjs/renderer";

// Main thread
await storeRenderContext(redis, requestId, { route, props });

// Worker thread
const context = await getRenderContext(redis, requestId);
const html = await render(context);
await storeRenderResult(redis, requestId, html);

// Cleanup
await cleanupRenderContext(redis, requestId);

HTML shell wrapper

import { wrapInShell } from "@scratchyjs/renderer";

const fullHtml = wrapInShell(renderedBody, {
  title: "My App",
  lang: "en",
  head: '<meta name="description" content="My App">',
});

API

rendererPlugin (Fastify plugin)

Registers a Piscina pool and decorates the server with fastify.piscina and fastify.runTask(). The pool is closed automatically on server shutdown.

Options (RendererPluginOptions)

| Option | Default | Description | | ------------------------ | -------------- | -------------------------------------- | | worker | — | Absolute path to the worker entry file | | minThreads | 2 | Minimum live worker threads | | maxThreads | max(4, cpus) | Maximum worker threads | | idleTimeout | 60000 | ms before an idle worker is terminated | | taskTimeout | 30000 | ms before a task is aborted | | maxOldGenerationSizeMb | 512 | V8 heap limit per worker (MB) |

createSSRHandler(options?): FastifyRouteHandler

Returns a Fastify route handler that dispatches an SSR task via fastify.runTask() and sends the resulting HTML.

runSsgPipeline(options): Promise<SsgPipelineResult>

Generates static HTML for a list of routes and writes them to outputDir.

createSharedBuffer(payloadSize?): SharedBuffer

Creates a SharedArrayBuffer-backed buffer for zero-copy inter-thread communication.

writeToBuffer(shared, data): void

Serialises data to JSON, writes it into the shared buffer, and signals DATA_READY.

readFromBuffer<T>(shared, timeoutMs?): T

Waits for DATA_READY, deserialises, and returns the payload. Throws on timeout or error status.

BufferStatus

Constants: IDLE, DATA_READY, CONSUMED, ERROR.

storeRenderContext / getRenderContext / storeRenderResult / cleanupRenderContext

Redis helpers for distributed main-thread ↔ worker communication with configurable TTLs.

wrapInShell(body, options): string

Wraps a rendered HTML body in a full HTML shell.

Documentation

https://scratchyjs.com/rendering