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

sync-gdrive

v1.2.0

Published

Module to synchronise a file or directory in Google Drive with the local file system

Downloads

6

Readme

Sync GDrive

This is a library to allow you to synchronise a file or directory in Google Drive with the local file system. Currently this solution provides a one way sync from Google Drive to the local file system.

This code was orginally developped for the maison-notman-house API server, but it was felt that it would have more value as module that could be used by other projects.

The orginal solution had been created with the idea of using Google Drive as a simple CMS and then periodically synchronising the specified folder with the local file system, for use with the running API server.

This current version is written in Typescript and leverages async/await internally.

WARNING Before using, note that any files or folders in your local sync folder will be overwitten, so ensure you start with an empty folder.

Usage:

// Regular JS
const gdriveSync = require('sync-gdrive');

const keyConfig = {
  clientEmail: process.env.GOOGLE_CLIENT_EMAIL,
  privateKey: process.env.GOOGLE_PRIVATE_KEY
};

const options = {};

await syncGDrive(fileOrFolderId, destFolder, keyConfig, options);
// Typescript
import syncGDrive, { IKeyConfig } from 'sync-gdrive';

const keyConfig: IKeyConfig = {
  clientEmail: process.env.GOOGLE_CLIENT_EMAIL,
  privateKey: process.env.GOOGLE_PRIVATE_KEY
};

const options = {};

await syncGDrive(fileOrFolderId, destFolder, keyConfig, options);

Where:

  • fileOrFolderId id of directory or file on Google Drive

  • destFolder local folder that should be synchronised. Note any existing files in this folder will be wiped if they don't correspond to something upstream.

  • keyConfig Your key generated from the Google API console.

  • options optional parameter, allowing for tweaking of certain functionality:

    • verbose: if true displays debug info (default: false)
    • callback: callback when a file is synced (default: undefined)
    • docsFileType: file type to use when exporting a Google Doc (default: docx )
    • sheetsFileType: file type to use when exporting a Google Sheet (default: xlsx)
    • slidesFileType: file type to use when exporting Google Slides (default: pptx)
    • fallbackGSuiteFileType: file type to use when exporting other GSuite files (default: pdf),
    • abortOnError: whether to abort on an error,
    • logger: logger to use in verbose mode, must have support for debug, warn and error functions
    • sleepTime: Rate limiter. How long to wait, in milleseconds, after downloading a file. (default: 500)
    • supportAllDrives: whether the requesting application supports both My Drives and shared drives. If false, then shared drive items are not included in the response
    • includeItemsFromAllDrives: whether shared drive items should be included in results. If not present or set to false, then shared drive items are not returned

Further reading:

CLI

There is now a basic CLI, so you can use this package without needing to integrate it into a JS application first. You can install it either globally (assuming a Unix type environment):

npm install -g sync-gdrive
export GOOGLE_CLIENT_EMAIL="xxxxxx"
export GOOGLE_PRIVATE_KEY="xxxxxx"
sync-gdrive "filefolderid" "dest_folder"

or if you already installed it as a dependency of your project:

export GOOGLE_CLIENT_EMAIL="xxxxxx"
export GOOGLE_PRIVATE_KEY="xxxxxx"
./node_modules/.bin/sync-gdrive "filefolderid" "dest_folder"

Targeted environments

This project will not work in the browser, due to dependencies on the file system.

Targeted node.js versions are 18+ .

Contributions & Feedback

Contributions and feedback is welcome. Please open a ticket in the issue tracker for the project on GitHub

Contributors

  • Andre John Mas

License

Licensed using the MIT license. See: https://opensource.org/licenses/MIT