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

node-cloudfs-drive

v1.0.9

Published

Wrapper to simplify interaction with google drive apis

Downloads

4

Readme

node-cloudfs-drive

GitHub issues GitHub stars GitHub license Twitter

Library implementing Promises to make working with Google drive more like working with a local fs (paths, folders, files, and standard operations.) Other cloud services to come as I have time or others contribute. Please see the CONTRIBUTE.md file.

HISTORY

This project wouldn't exist if not for https://github.com/mhdawson/google-drive-wrapper. I did fork initially, but so much changed so quickly that I decided a PR made no sense and this was to live on as its own project. Thanks to Michael Dawson for giving me a kick-off point with this.

ISSUES AND SUPPORT

Please see CONTRIBUTING.md

The Google Drive constructor requires:

  • auth - googleAuth.OAuth2 object to be used to access the google services (see not below)
  • google - instance of googleapis to be used to access the google services

Caching is provided by node-cache and reduces API calls substancially for getMetaForFilename as well as making things almost instant compared to external API calls, much as a reverse proxy between this and the API would. See options in code below if you'd like to tweak the cache timeout values.

Throttling is provided by promise-ratelimit. This helps cope with bursty jobs at the expense of latency, but is required to deal with API limits. Keep in mind that running multiple instances of this module (clustering) will multiple the rate of hits on the API.

USE

npm install node-cloudfs-drive --save
let { google } = require('googleapis'),
    ncfsOptions = {
        throttle: 2000,
        cacheTTL: 60 * 60 * 24,
        cacheCheckperiod: 60 * 60,
        pageSize: 20,
        backoff: {
            retries: 3,
            factor: 3
        }
    }; // These are the present defaults

//I suggest using someone elses's token generator until mine is at least 1.0.0, but it does work for testing
require('oauth-token-generator-google')( googleAuthCredentialsPath ).then( auth => { 
	let drive = require('node-cloudfs-drive').Drive( auth, google, ncfsOptions );
	// drive will expose this projects helper methods as well as the actual the googleapis drive object
    
    drive.mkdir( testFolderA )
    .then( folder => {
		// Your Google Drive folder object
    })
    .catch(err => {
    	console.error(err);
    });
})
.catch(err => { 
	console.error(err);
});

GOOGLE AUTH TOKEN

Overview: https://developers.google.com/identity/protocols/OAuth2

After 3 attempts with node.js and Googel APIs, I decided to learn oauth a bit more and ended up writing my own library to manage the tokens for me. A big part of this was just my ignorance and lack of explanations that worked for me (turns out that the Google API version used in various samples/projects was a big factor here). Given my experience and the tutorials out there which can provide more detail, I won't get into a lot of detail but I do want to summarize what I've learned in recent history. Following other tutorials on the web, you will want to generate a client_secret.json file which Google will provide for you to download from the Google Developer console https://developers.google.com/identity/protocols/OAuth2. If you use the same oauth library this projects test suite does, you will place that client_secret.json file in a folder called private at the root of this/your project, and you reference that file when you instantiate the oauth client. The library will attempt to use this client_secret.json file to retrieve tokens from Google which will then be saved next to the .json file with the same name, but .token extension and used in future constructor calls and to renew tokens. This library will not only help you create that token, but will look for it and attempt to use it when it is available. This library takes a novel approach to retrieving the initial token by prompting you in a node/webkit development console with a URL to visit and asking you to bring the code from that URL back to the console, then assign it to an object before resuming the debugger (directions are provided on the console in this mode). To that end, you can use the commands npm run dev or npm test:dev to run this library and connect with the console so that you can provide the code needed to retrieve a token. This manual process only needs to be done to retrieve the initial token so it is more of a utility in that respect. Once you have the token you can use that file in other projects by moving it (can't use it in many places at typically). More discussion about tokens is out of the scope of this document.