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

gdrive-node

v1.1.0

Published

Simple way to upload and manage google drive files

Downloads

9

Readme

Node Google Drive API

This is a simple google drive api using node. Accessing google drive api made simple using this node structure.

This is an open source repository and everyone is welcome to extend this repository with MIT License. This repository is using official google drive apis and made simple for further uses. Please visit https://developers.google.com/drive/api/v3/quickstart/nodejs for more information.

Features

  • Auto Auth
  • Manual Authentication (Use your web or console validation)
  • Upload File in root folder or specific folder
  • List File
  • Create Folder in root folder or specific folder

How to Use

Simple Clone this repository
  1. Go to https://console.developers.google.com/
  2. Create a project if not yet created or choose existing one
  3. Click on Enable APIS and Services and enable gooogle drive api
  4. Click on Credentials (Right Sidebar menu)
  5. Click on create credential
  6. Select OAuth Client ID
  7. From Dropdown Application type select Tvs and Limited input device
  8. Click on Create
  9. Now on Credentials page click on download icon in OAuth 2.0 Client IDs section
  10. rename this to credentials.json
  11. open config.js inside modules folder and set the path for credential_path see modules folder function for help

Include index.js where you want to use

const drive = require('./index'); 
var config = require('./config'); ///your config file
Using NPM : npm i gdrive-node
  1. Follow the above procedure to get your credentials.json from the google developer console
  2. create a config.js file and paste : exports.creds = "credentials.json"
  3. create app.js file and paste following code
const drive = require('gdrive-node'); 
var config = require('./config'); ///your config file
  • you can also use .env file instead of config.js
Now Call the following functions to operate.
  1. Authentication

drive.auth(config.creds)
.then((accesstoken)=>{

//do whatever you want to do with google api

})
  1. Upload file use 'false' as 5th parameter for root directory or pass folder id for parent folder id
drive.upload(config.creds, 'test123.pdf', 'files/test.pdf', 'application/pdf', false, function(data){
	console.log('File uploaded successfully,  File id is : '+ data);
}); 
  1. Create Folder : use 'false' for root directtory or pass folder id for parent folder id
drive.createFolder(config.creds,'my test folder', false, function(id){
	console.log(id);
})
  1. Manually Authentication
const readline = require('readline'); //for manually verification only

//Manual Authentication 
drive.auth_manual(config.creds)
.then((auth_url)=>{
	if(!auth_url)
	{
		console.log("You are already signed in, you can delete token.json to sign in from different accout");
	}
	else
	{
	//get the auth url by calling auth_manaual() function and get the code by clicking or redirecting to that code also you can usue a web check in form to get code 
	console.log('Click here:', auth_url);
	  const rl = readline.createInterface({
	    input: process.stdin,
	    output: process.stdout,
	  });
	  rl.question('Enter the code from that page here: ', (code) => {
	  rl.close();
	  	drive.saveAccessToken(code);  //a separate function to save token 
	});

	}
});
More Coming Soon