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

fs-gdrive

v1.3.0

Published

A file system-like interface for Google Drive operations in Node.js

Downloads

25

Readme

npm version npm downloads GitHub stars License


fs-gdrive, is a Node.js package that provides a file system-like interface for interacting with Google Drive. It simplifies operations such as reading, writing, and managing files and directories in Google Drive, making it easier to integrate Google Drive functionality into your Node.js applications.

Features

  • Connect to Google Drive using service account authentication
  • Read directory contents
  • Create directories
  • Read and write files
  • Delete files and directories
  • Rename or move files and directories
  • Get file/directory stats
  • Search for files and directories based on various criteria
  • Copy files

Installation

npm install fs-gdrive

Usage

First, import the GDrive class:

import { GDrive } from 'fs-gdrive'; // esm
// OR
const { GDrive } = require('fs-gdrive'); // cjs

Then, create an instance of GDriveFS with your Google Drive authentication details:

const fsGDrive = new GDrive({
  folderId: 'your-root-folder-id',
  auth: {
    email: '[email protected]',
    privateKey: 'your-private-key',
  },
});

Connect to Google Drive:

await fsGDrive.connect();

Now you can use various methods to interact with Google Drive:

// Read directory contents
const files = await fsGDrive.readdir('/path/to/directory');

// Create a directory
await fsGDrive.mkdir('/path/to/new/directory');

// Write a file
await fsGDrive.writeFile('/path/to/file.txt', 'File content');

// Read a file
const content = await fsGDrive.readFile('/path/to/file.txt');

// Delete a file or directory
await fsGDrive.unlink('/path/to/file-or-directory');

// Rename or move a file or directory
await fsGDrive.rename('/old/path', '/new/path');

// Get file or directory stats
const stats = await fsGDrive.stat('/path/to/file-or-directory');

// Search for files
const searchResults = await fsGDrive.search({
  name: 'example',
  mimeType: 'text/plain',
  minSize: 1000,
  maxSize: 10000,
  modifiedAfter: new Date('2023-01-01'),
  modifiedBefore: new Date('2023-12-31'),
});

// Copy a file
await fsGDrive.copy('/path/to/source/file.txt', '/path/to/destination/file.txt');

API Reference

constructor(options)

Creates a new GDrive instance.

  • options.folderId: The root folder ID in Google Drive.
  • options.auth.email: Service account email.
  • options.auth.privateKey: Private key for authentication.

connect()

Connects to Google Drive using the provided authentication details.

readdir(path = '/')

Reads the contents of a directory.

mkdir(path)

Creates a new directory.

writeFile(path, content)

Writes content to a file.

readFile(path)

Reads the content of a file.

unlink(path)

Deletes a file or directory.

rename(oldPath, newPath)

Renames or moves a file or directory.

stat(path)

Retrieves the stats of a file or directory.

search(options, path = '/')

Searches for files and directories based on specific criteria.

copy(sourcePath, destinationPath)

Copies a file from one location to another.

Error Handling

All methods in GDrive throw errors when operations fail. It's recommended to use try-catch blocks or .catch() methods when using these functions to handle potential errors.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.