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

@photostructure/fs-metadata

v0.1.3

Published

Cross-platform native filesystem metadata retrieval for Node.js

Downloads

234

Readme

@photostructure/fs-metadata

A cross-platform native Node.js module for retrieving filesystem metadata, including mount points, volume information, and space utilization statistics.

Built and supported by PhotoStructure.

npm version Build GitHub issues Known Vulnerabilities Node-API v9 Badge View on GitHub

Features

Installation

npm install @photostructure/fs-metadata

Usage

import {
  getVolumeMountPoints,
  getVolumeMetadata,
} from "@photostructure/fs-metadata";

// List all mounted volumes
const mountPoints = await getVolumeMountPoints();
console.dir({ mountPoints });

// Get metadata for a specific volume
const volumeMetadata = await getVolumeMetadata(mountPoints[0]);
console.dir({ volumeMetadata });

If you're using CommonJS:

const {
  getVolumeMountPoints,
  getVolumeMetadata,
} = require("@photostructure/fs-metadata");

// Usage is the same as the ESM example above 
// (except of course no top-level awaits!)

API

Read the API here

Options

Debug Logging

Set NODE_DEBUG=fs-meta or NODE_DEBUG=photostructure:fs-metadata. The native debuglog determines if debug logging is enabled. Debug messages from both JavaScript and native code are sent to stderr.

Timeouts

Operations use a default timeout, which may need adjustment for slower devices like optical drives (which can take 30+ seconds to spin up).

Windows can block system calls when remote filesystems are unhealthy due to host downtime or network issues. To handle this, we use a separate thread per mountpoint to check volume health status. While this approach uses more resources than the async N-API thread, it enables reliable timeouts for operations that would otherwise hang indefinitely.

Timeout duration may apply per-operation or per-system call, depending on the implementation.

System Volumes

Each platform handles system volumes differently:

  • Windows provides explicit metadata for "system" or "reserved" devices, though C:\ is both a system volume and typical user storage
  • Linux and macOS include various system-only mountpoints: pseudo devices, snap loopback devices, virtual memory partitions, and recovery partitions

This library uses heuristics to identify system volumes. See Options for default values and customization.

Note: getAllVolumeMetadata() returns all volumes on Windows but only non-system volumes elsewhere by default.

Platform-Specific Behaviors

This module's results are inherently platform-specific. Here are some things to keep in mind:

Mount Points

Windows

  • Mount points are drive letters with trailing backslash (e.g., C:\, D:\)
  • Network shares appear as mounted drives with UNC paths
  • Volume GUIDs are available through Windows API
  • Hidden and system volumes may be included

macOS

  • Uses forward slashes for paths (e.g., /, /Users)
  • Volume UUIDs may be available through the DiskArbitration framework
  • Time Machine volumes should be detected and handled appropriately

Linux

  • Uses forward slashes for paths (e.g., /, /home)
  • Network mounts (NFS/CIFS) handled through mount table
  • If GIO support is installed, it will be queried for additional mountpoints and volume metadata
  • Depending on your distribution, you may want to use { linuxMountTablePath: "/etc/mtab" } instead of the default, /proc/mounts.
  • UUID detection is via libblkid, which must be installed.

Volume Metadata

Windows

  • Volume status from GetDriveType
  • Size information from GetDiskFreeSpaceEx
  • Volume information (label, filesystem) from GetVolumeInformation
  • fstype will be NTFS for remote filesystems, as that's how Windows presents the local volume. Fixing this to be more accurate requires additional heuristics that have diminshing returns.
  • The UUID is attempted to be extracted from the partition UUID, but if this is a remote volume, or system permissions do not provide access to this, we will fall back to returning the volume serial number that the operating system assigns. You can tell that it's a serial number UUID in that it only contains 8 characters (32 bits of entropy).

macOS

  • Size calculations via statvfs
  • Volume details through DiskArbitration framework
  • Network share detection via volume characteristics

Linux

  • Size information from statvfs
  • Filesystem type from mount table and from gio
  • Block device metadata via libblkid
  • Network filesystem detection from mount options
  • Optional GIO integration for additional metadata
  • Backfills with lsblk metadata if native code fails

License

MIT

Contributing

See CONTRIBUTING.md on GitHub.

Security

See SECURITY.md on GitHub.