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

better-gdrive

v0.1.2

Published

Download files from public Google Drive. Get direct download URLs or fetch as Blob/Buffer. No OAuth required.

Readme

better-gdrive

Node npm License

Download files from public Google Drive without OAuth: list a folder, get a file in memory (blob/buffer), read metadata, or save directly to disk. Lightweight, no runtime dependencies, optimized (streaming, low memory).

If this package is useful to you, a star on the repo is always appreciated.


Installation

npm install better-gdrive

Requirements: Node ≥ 18. Files or folders must be shared with "Anyone with the link".

When Google shows the "Virus scan warning" page for a file, the library automatically parses the confirmation form and fetches the real file—no extra step on your side.


API — Tutorial by function

| listFiles | getFile | getFileMetadata | downloadFile | toFileId | |----------------------------------------|----------------------------------------|--------------------------------------------------|--------------------------------------------------|---------------------------|

All functions that take a file accept either an ID (e.g. abc123xyz) or a share link (the ID is extracted automatically). Cancellation is supported via { signal: AbortSignal } on every call.


listFiles(folderId, options?)

Lists files in a public folder (share link or folder ID).

Returns: Promise<ListFileEntry[]> with { id: string, name?: string } (name is set when Drive’s HTML provides it).

import { listFiles } from "better-gdrive";

const files = await listFiles("https://drive.google.com/drive/folders/1ABC...");
// or
const files = await listFiles("1ABC...");

console.log(files);
// [{ id: "xyz123", name: "report.pdf" }, { id: "abc456", name: "data.csv" }, ...]

getFile(fileId, format, options?)

Gets the file in memory as a Blob (browser or Node) or Buffer (Node).

  • format: "blob" | "buffer"
import { getFile } from "better-gdrive";

// As buffer (Node)
const buffer = await getFile("FILE_ID", "buffer");
fs.writeFileSync("./out.pdf", buffer);

// As blob (Node or browser)
const blob = await getFile("FILE_ID", "blob");
const url = URL.createObjectURL(blob);

getFileMetadata(fileId, options?)

Gets metadata without downloading the file (HEAD / minimal Range request).

Returns: Promise<FileMetadata> with filename?, size?, mimeType?, lastModified? (Date).

import { getFileMetadata } from "better-gdrive";

const meta = await getFileMetadata("FILE_ID");
console.log(meta.filename);   // "document.pdf"
console.log(meta.size);       // 1024000
console.log(meta.lastModified); // Date

downloadFile(fileId, path, options?)

Saves the file directly to disk (Node only). Uses streaming to limit memory usage.

import { downloadFile } from "better-gdrive";

await downloadFile("FILE_ID", "./downloads/document.pdf");

toFileId(input)

Extracts the Drive ID from a share link, or returns the string as-is if it’s already an ID.

import { toFileId } from "better-gdrive";

const id = toFileId("https://drive.google.com/file/d/1abcXYZ/view?usp=sharing");
// "1abcXYZ"

Errors: GDriveDownloadError

On failure (bad HTTP status, no download link, etc.), the package throws GDriveDownloadError (subclass of Error) with:

  • message
  • statusCode (optional)
  • fileId (optional)
import { getFile, GDriveDownloadError } from "better-gdrive";

try {
  const buffer = await getFile("BAD_ID", "buffer");
} catch (err) {
  if (err instanceof GDriveDownloadError) {
    console.error(err.fileId, err.statusCode);
  }
  throw err;
}

Cancellation: signal

All functions that accept options support options.signal (AbortSignal) to cancel the request.

const controller = new AbortController();
setTimeout(() => controller.abort(), 5000);

const files = await listFiles("FOLDER_ID", { signal: controller.signal });

Exported types

  • ListFileEntry: { id: string; name?: string } (returned by listFiles)
  • FileMetadata: { filename?; size?; mimeType?; lastModified? } (returned by getFileMetadata)

License

MIT