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

runtime-save

v1.1.1

Published

A JavaScript library to save files with runtime-awareness

Readme

runtime-save

A lightweight JavaScript library that provides a unified file-saving interface across different JavaScript environments (browser and Node.js).

npm version License: MIT

Features

  • Environment Detection: Automatically detects whether your code is running in a browser or Node.js
  • Browser Support:
    • Uses the modern File System Access API when available
    • Falls back to the download attribute method for broader compatibility
  • Node.js Support: Saves files to the file system using the native fs module
  • Flexible Content Types: Accepts Blob, string, or Buffer input types
  • TypeScript Support: Fully typed API with TypeScript declarations included

Installation

# npm
npm install runtime-save

# pnpm
pnpm add runtime-save

Usage

Basic Example

import { saveFile } from "runtime-save";

// Save a string to a file
await saveFile("hello.txt", "Hello, World!");

// Save a Blob to a file (works in both browser and Node.js)
const blob = new Blob(["CSV data"], { type: "text/csv" });
await saveFile("data.csv", blob);

// In Node.js, you can also save a Buffer
const buffer = Buffer.from("Buffer content");
await saveFile("file.bin", buffer);

// Specify a save path (only works in Node.js)
await saveFile("report.pdf", pdfContent, "/path/to/save/directory/");

Browser Environment

In a browser, runtime-save will:

  1. Try to use the File System Access API first (modern browsers)
  2. Fall back to using an anchor tag with the download attribute

Node.js Environment

In Node.js, runtime-save will:

  1. Convert the content to a Buffer if it isn't already
  2. Save to the specified path or to the current working directory if no path is provided

API

saveFile(filename, content, savePath?)

Saves content to a file, with environment-appropriate behavior.

Parameters

  • filename (string): The name of the file to be saved
  • content (Blob | string | Buffer): The content to save
  • savePath (string, optional): The directory where the file should be saved (Node.js only)

Returns

  • Promise<void>: Resolves when the file has been saved

Browser Compatibility

  • Modern Browsers (Chrome 86+, Edge 86+): Full support with File System Access API
  • All Modern Browsers: Fallback support using download attribute

Contributing

Please see CONTRIBUTING guide for details on how to contribute to this project.

Code of Conduct

This project adheres to a Code of Conduct. By participating, you are expected to uphold this code.

License

This project is licensed under the MIT License.