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

zen-fs-remotestoragejs

v1.3.27

Published

RemoteStorage.js backend for zen-fs - distributed file system interface

Readme

zen-fs-remotestoragejs

A ZenFS backend for RemoteStorage-compatible storage servers. Provides a full FileSystem interface over HTTP, with smart caching, ETag-based change detection, and optimized sync support.

Features

  • Full FileSystem API — readFile, writeFile, stat, readdir, mkdir, unlink, rmdir, and more
  • Smart caching — directory listing cache with ETag-based invalidation, existence cache, and persistent storage (localStorage / file)
  • Optimized for sync — implements shouldSync() with root ETag check + snapshot-based subtree pruning, so most sync checks need just 1 HTTP request
  • Precise mtime — millisecond-accurate modification times via .mtime sidecar files (invisible to upper layers)
  • Auto-retry — built-in retry with backoff for transient network errors
  • Browser & Node.js — works in both environments with no code changes
  • Standard RemoteStorage protocol — compatible with any RemoteStorage-compatible server (5apps, own instance, etc.)

Installation

npm install zen-fs-remotestoragejs

Requires @zenfs/core >= 2.3.3.

Usage

Basic setup

import {
  RemoteStorageFileSystem,
  createRemoteStorageFileSystem,
} from 'zen-fs-remotestoragejs';

// Recommended factory function:
const fs = createRemoteStorageFileSystem({
  href: 'https://storage.5apps.com/',
  token: 'your-bearer-token',
  basePath: '/public/', // optional, scopes all operations
});

// Or instantiate directly:
const fs2 = new RemoteStorageFileSystem({
  href: 'https://example.com/storage/',
  token: 'your-token',
});

With ZenFS configure

import { configure, fs } from '@zenfs/core';
import { RemoteStorageFileSystem } from 'zen-fs-remotestoragejs';

await configure({
  mounts: {
    '/remote': {
      backend: RemoteStorageFileSystem,
      href: 'https://storage.5apps.com/',
      token: 'your-token',
      basePath: '/public/',
    },
  },
});

// Read a file
const data = await fs.promises.readFile('/remote/notes.txt', 'utf-8');

// Write a file
await fs.promises.writeFile('/remote/notes.txt', 'Hello RemoteStorage!');

// List directory
const files = await fs.promises.readdir('/remote/docs/');

With zen-fs-sync

import { SyncPair, SyncDirection } from 'zen-fs-sync';
import { createRemoteStorageFileSystem } from 'zen-fs-remotestoragejs';

const remoteFS = createRemoteStorageFileSystem({
  href: 'https://storage.5apps.com/',
  token: 'your-token',
  basePath: '/public/my-app/',
});

// Sync local IndexedDB with RemoteStorage
const pair = new SyncPair(localFS, remoteFS, {
  direction: SyncDirection.BiDirectional,
  pollIntervalMs: 300000, // 5 minutes
});

// shouldSync() is implemented — remote polls are cheap (1 HEAD request)
pair.watch();

Configuration

| Option | Type | Default | Description | |--------|------|---------|-------------| | href | string | required | Base URL of the RemoteStorage server | | token | string | required | Bearer token for authentication | | basePath | string | undefined | Base path prefix for all file operations (e.g. '/public/', '/username/app_data/'); the sync baseline is derived from it (root when set, app_data/ when empty) | | headers | Record<string, string> | undefined | Extra HTTP headers to include in every request | | timeout | number | 30000 | Request timeout in milliseconds | | preciseMtime | boolean | true | Enable millisecond-precision mtime via .mtime sidecar files | | persistCache | boolean | true | Persist directory listing cache to localStorage (browser) or file (Node.js) | | cacheFile | string | .zen-fs-remotestorage-cache.json | Path for persisted cache file (Node.js only) |

How Caching Works

The backend uses a multi-layer caching strategy to minimize network requests:

  1. Directory listing cache — readdir() results are cached with ETags. On subsequent calls, the ETag is sent via If-None-Match; if the server returns 304, the cached listing is reused. This means stat() calls for files in a cached directory need no extra network requests — metadata comes directly from the listing entry.

  2. Existence cache — exists() results are cached with separate TTLs for positive (5 min) and negative (1 min) results. This avoids repeated HEAD requests for the same path.

  3. Persistent cache — The directory listing cache is saved to localStorage (browser) or a JSON file (Node.js), so a warm page load needs zero network requests for most stat() and readdir() calls.

Sync Optimization

The backend implements the SyncableFS interface with several optimizations:

  • shouldSync() — sends a single HEAD request to the root folder and compares ETags. If unchanged, returns false and no full sync is needed.
  • createSnapshot() — builds a full file tree with ETags by walking directories. Uses subtree pruning: if a folder's ETag hasn't changed since the last snapshot, its entire subtree is skipped.
  • getRevision() — returns a file's ETag from the cached directory listing when available, falling back to HEAD only when necessary.
  • writeFileWithMtime() — preserves precise mtime via sidecar files, so sync can compare timestamps accurately.

Exports

| Export | Description | |--------|-------------| | RemoteStorageFileSystem | Main class (also the default export) | | createRemoteStorageFileSystem(config) | Factory function | | createUniversalSyncFileSystem, adaptFileSystem | Sync adapter helpers | | RemoteStorageError | Base error class | | FileNotFoundError | Thrown on 404 for files | | DirectoryNotFoundError | Thrown on 404 for directories | | FileExistsError | Thrown on 409 conflict | | AuthenticationError | Thrown on 401 | | PermissionDeniedError | Thrown on 403 | | Path utilities | normalizePath, joinPath, getBasename, getParentPath, isValidPath, and more |

Error Handling

All errors thrown by the backend are instances of RemoteStorageError or its subclasses:

import { RemoteStorageFileSystem, FileNotFoundError } from 'zen-fs-remotestoragejs';

try {
  await fs.readFile('/nonexistent.txt');
} catch (error) {
  if (error instanceof FileNotFoundError) {
    console.log('File does not exist');
  } else if (error instanceof AuthenticationError) {
    console.log('Token expired or invalid');
  }
}

License

MIT