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

muggler

v1.0.0

Published

Muggler is a node.js module for using Google Drive API in a simplified way.

Downloads

5

Readme

Muggler

Muggler is a node.js module for using Google Drive API in a simplified way.

NOTE: Muggler process only multipart/form-data. Use attribute enctype='multipart/form-data' in form.

Before you start

Create project on Google Cloud Platform and enable Google Drive API.
Check this for step by step tutorial.

Getting started

Installation

$ npm install muggler --save

Requiring module

const config  = require('../path/to/secret/config.json');
const muggler = require('muggler')({
  email: config.client_email,
  key: config.private_key
});

Methods

listAll

app.get('/', function (req, res) {
  muggler.listAll({infolder: 'folderid'}, function (err, resp) {
    if (err) {
      console.log(err);
    }
    res.send(resp);
  })
})
  • infolder accepts 'string' and 'array' value only.
  • for root folder of drive use root as 'folderid'.
  • infolder: [folder1id, folder2id] will get files whose parent folder is either folder1 or folder2 that is, all files inside folder1 and folder2 will be in response.
// Response structure
{
  status: 'status of operation',
  mug: [
    {
      kind: 'kind of file',
      id: 'id of file',
      name: 'name of file',
      mimeType: 'type of file'
    },
    {
      kind: 'kind of file',
      id: 'id of file',
      name: 'name of file',
      mimeType: 'type of file'
    }
  ]
}

upOne

app.post('/', function (req, res) {
  muggler.upOne({fromfield: 'fieldname', infolder: 'folderid'}, req, function (err, resp) {
    if (err) {
      console.log(err);
    }
    res.send(resp);
  })
})
  • fromfield accepts 'string' value only.
  • fieldname should be name of the input field which will accept file in form.
  • infolder accepts 'string' and 'array' value only.
  • for root folder of drive use root as 'folderid'.
  • infolder: [folder1id, folder2id] will upload file to folder1 and folder2 both with same id.
// Response structure
{
  file: {
    fieldname: "name of input field",
    originalname: "original name of file",
    encoding: "encoding type",
    mimetype: "type of file",
    destination: "temporary destination",
    filename: "changed name of file",
    path: "tempporary location of file",
    size: 'size of file'
  },
  status: "status of operation",
  mug: {
    id: "id of file",
    name: "name of file",
    mimeType: "type of file",
    size: 'size of file',
    parents: [
      "parent folder id"
    ],
    url: "url of file"
  },
  body: {
    otherFormField: "value in field"
  }
}

delOne

app.post('/', function (req, res) {
  muggler.delOne({fileid: 'id of file'}, req, function (err, resp) {
    if (err) {
      console.log(err);
    }
    res.send(resp);
  })
})
  • fileid accepts 'string' value only.
// Response structure
{
  status: "status of operation",
  mug: []
}

Something to note

  • Service Account has its own Google Drive storage so files uploaded using Muggler will not be there in your own Google Drive.
  • Create folder in your Google Drive manually and share it with Service Account using client_email.
    • Open that folder and looking into its URL for its ID.
    • Files uploaded using Muggler into this folder will be visible in your own Google Drive now but storage of Service Account's Google Drive will be used. That is, originally file is created in Service Account's Google Drive as it is uploaded by Service Account but its reference is visible in your own Google Drive also because folder is shared.
    • If you manually delete any file from this shared folder then it will just delete the reference and original file will remain unaffected. To delete that file permanently use Service Account that is, using Muggler.