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

google-drive-dwn

v0.1.2

Published

Google Drive File Downloader

Downloads

24

Readme

google-drive-dwn (Google Drive File Downloader)

Purpose

google-drive-dwn is a simple way to download a shared file from Google Drive.

The module can perform:

  • downloading files with binary content
  • downloading Google Doc files and convert them to the specified format
  • restricting maximum file size
  • assigning unique file names

Note: This module was developed for Google Drive API v3

You can use the module to download files one by one. This doesn't support multiple downloading.

Installation

Before starting you have to install googleapis

npm install googleapis@27 --save

When googleapis has been installed you can run:

npm install google-drive-dwn --save

NOTE: During the installation you will be asked for a few questions. So you should be prepared.

1. Please put credentials.json in the root of your app and press Enter

At this point, you should enable the Drive API, download JSON-file (Google Console - APIs & Services - Credentials) and ensure it is named credentials.json (see below)

Credentials

Put the file and press Enter

2. Enter the scopes

List of scopes

If you want to enter more then one scope you should separate them with a comma

For example: https://www.googleapis.com/auth/drive.readonly,https://www.googleapis.com/auth/drive.metadata

3. Browse to the provided URL in your web browser.

If you are not already logged into your Google account, you will be prompted to log in. If you are logged into multiple Google accounts, you will be asked to select one account to use for the authorization.

Click the Accept button.

Copy the code you're given, paste it into the command-line prompt, and press Enter.

It will create a token.json in the root of your app

After installation

Now you can move and/or rename the files credentials.json and token.json

You will need them later when you are ready to use the module.

Usage

const googleDrive = require('google-drive-dwn')
const drive = googleDrive(config)
...
const result = await drive('fileId')

The config is an object that contains the following properties:

| Name | Type | Description | | --- | --- | --- | | scopes| Array| You should use the same scopes that you entered during installation | | credentialsPath| String | The path to your credential file | | tokenPath| String | The path to the created token file | | fileDir| String | The directory for downloading | | mimeTypes| Object | The list of mimeTypes | | maxFileSize| Number | The size of the file's content in bytes |

Return

It returns an object that contains the following properties:

| Name | Type | Description | | --- | --- | --- | | _FILENAME| String| The file name | | _EXT| String | The file extension | | _FILEPATH| String | The file path including name and extension | | _MIMETYPE| String | The mimeType of source file | | _EXPORTTYPE| String | The mimeType of output file |

Example:

const googleDrive = require('google-drive-dwn');

const drive = googleDrive({
    scopes: ['https://www.googleapis.com/auth/drive.readonly'],
    tokenPath: './sensitive_data/credentials.json',
    credentialsPath: './sensitive_data/token.json',
    fileDir: './statics/files',
    mimeTypes: {
      "application/vnd.google-apps.document": {
        "ext": "docx",
        "exportType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
      },
      "application/vnd.google-apps.spreadsheet": {
        "ext": "xlsx",
        "exportType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
      },
      "application/msword": {
        "ext": "doc"
      },
      "application/vnd.ms-excel": {
        "ext": "xls"
      },
      "application/pdf": {
        "ext": "pdf"
      },
      "image/png": {
        "ext": "png"
      },
      "image/jpeg": {
        "ext": "jpg"
      }
    },
    maxFileSize: 5e+7
});

drive('fileId')
  .then(res => console.log(res))
  .catch(err => console.error(err))