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

@k2b/filegate

v3.0.0

Published

TypeScript client for the Filegate filesystem gateway

Readme

@k2b/filegate

TypeScript client for Filegate. Use it from trusted server runtimes to call the Filegate REST API, and from browsers only with scoped direct upload/download URLs minted by your application server.

Filegate keeps files as normal Linux files on configured mounts. The client covers path and ID lookup, direct URLs, upload sessions, transfers, search, operations, declarative configuration, S3 credentials, activity, and stats.

Install

npm i @k2b/filegate

Server client

Use the default instance when FILEGATE_URL and FILEGATE_TOKEN are available in the server runtime:

import { filegate } from "@k2b/filegate/client";

process.env.FILEGATE_URL = "http://127.0.0.1:8080";
process.env.FILEGATE_TOKEN = "dev-token";

const roots = await filegate.paths.get();
const caps = await filegate.capabilities.get();

Use an explicit instance for dependency injection:

import { Filegate } from "@k2b/filegate/client";

const fg = new Filegate({
  baseUrl: "https://filegate.internal.example",
  token: "<filegate-token>",
  fetchImpl: fetch,
});

const node = await fg.paths.get("photos/2026");

The client namespaces match the API surface:

| Namespace | Meaning | | --- | --- | | paths | Path-based lookup, upload, and directory listing. | | nodes | ID-based metadata, content, mkdir, delete, and metadata edits. | | uploads | One-shot direct upload URLs and resumable upload sessions. | | downloads | Scoped direct download URLs. | | transfers | Move and copy operations. | | search | Indexed path search. | | index | Index stats and rescan operations. | | stats | Runtime, mount, cache, filesystem, and process stats. | | system | Health, operational runtime, upload sessions, and version pruning. | | config | Configuration schema, desired/effective values, manifest plan and apply. | | s3Keys | S3 access-key creation, grants, rotation, and deletion. | | capabilities | Server upload/download limits for adaptive clients. | | versions | File version history on supported mounts. | | activity | Recent API activity from the bounded server ring buffer. |

Browser uploads

Do not expose the Filegate bearer token to browser code. The browser should ask your application server for permission to upload. The application server then creates direct Filegate upload URLs or direct upload sessions and returns the scoped credentials to the browser.

import { upload } from "@k2b/filegate/client";

await upload({
  files,
  path: "photos/inbox",
  allow: async (request) => {
    const response = await fetch("/api/filegate/uploads/allow", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(request),
    });
    return response.json();
  },
  onEvent: (event) => {
    console.log(event.type, event);
  },
});

The high-level helper uses the transfer shape from the allow response. Small files can use direct one-shot URLs. Larger files can use resumable sessions with parallel segment uploads. Conflict handling is explicit; skip-existing is the default.

For a single direct upload URL:

import { uploadDirect } from "@k2b/filegate/client";

await uploadDirect(uploadUrlFromYourServer, file, {
  onSuccess: ({ node }) => console.log(node.id),
});

Browser downloads

Mint the direct download URL on your application server and redirect the browser:

const direct = await fg.downloads.createDirectURL({
  nodeId: "<node-id>",
  expiresInSeconds: 5 * 60,
});

return Response.redirect(direct.downloadUrl, 303);

Direct file downloads support GET, HEAD, and byte ranges. Directory downloads stream tar archives.

Resumable sessions

Use upload sessions when you need resumable, parallel uploads with explicit commit:

const session = await fg.uploads.sessions.create({
  path: "videos/input.mov",
  size,
  checksum,
  segmentSize: 16 * 1024 * 1024,
  onConflict: "error",
});

for (const segment of session.segments) {
  await fg.uploads.sessions.segments.put({
    sessionId: session.id,
    index: segment.index,
    body: segmentBody,
    checksum: segmentChecksum,
  });
}

const committed = await fg.uploads.sessions.commit({ sessionId: session.id });
console.log(committed.node.id);

Segment PUTs are idempotent when the content matches. Commit is explicit and safe to retry after success.

Utilities

Pure helpers live under @k2b/filegate/utils and do not require a Filegate token:

import { uploads } from "@k2b/filegate/utils";

const checksum = await uploads.checksum.sha256(file);

Documentation

  • Project README: https://github.com/k2b-dev/filegate#readme
  • TypeScript guide: https://filegate.dev/docs/en/ts-sdk
  • HTTP routes: https://filegate.dev/docs/en/reference/http-routes