{"id":22004276,"url":"https://github.com/huasofoundries/node-google-drive","last_synced_at":"2025-05-05T17:23:47.689Z","repository":{"id":45958205,"uuid":"116174659","full_name":"HuasoFoundries/node-google-drive","owner":"HuasoFoundries","description":"Library to operate with Google Drive API v3 from Node.js, using system user tokens or personal keys","archived":false,"fork":false,"pushed_at":"2021-11-24T14:16:06.000Z","size":1977,"stargazers_count":58,"open_issues_count":33,"forks_count":26,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2024-10-16T08:08:02.873Z","etag":null,"topics":["google-drive","javascript","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HuasoFoundries.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-03T19:38:34.000Z","updated_at":"2024-08-29T05:43:19.000Z","dependencies_parsed_at":"2022-08-12T12:40:23.771Z","dependency_job_id":null,"html_url":"https://github.com/HuasoFoundries/node-google-drive","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuasoFoundries%2Fnode-google-drive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuasoFoundries%2Fnode-google-drive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuasoFoundries%2Fnode-google-drive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HuasoFoundries%2Fnode-google-drive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HuasoFoundries","download_url":"https://codeload.github.com/HuasoFoundries/node-google-drive/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227239621,"owners_count":17752498,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google-drive","javascript","nodejs"],"created_at":"2024-11-30T00:13:54.313Z","updated_at":"2024-11-30T00:13:54.986Z","avatar_url":"https://github.com/HuasoFoundries.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-google-drive\n\n[![Travis CI](https://travis-ci.org/HuasoFoundries/node-google-drive.svg?branch=master)](https://travis-ci.org/HuasoFoundries/node-google-drive)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FHuasoFoundries%2Fnode-google-drive.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2FHuasoFoundries%2Fnode-google-drive?ref=badge_shield)\n\nLibrary to operate with Google Drive API v3 from Node.js, using system user tokens or personal keys\n\nThis library is **heavily** inspired on [theozero](https://www.npmjs.com/~theozero)'s' [google-spreadsheet](https://www.npmjs.com/package/google-spreadsheet). No, I mean, really inspired. As in _blatantly copied_. The only difference being his library is to operate with google spreadsheets and this one is to interact with google drive.\n\nSo, basically, you can operate in two ways. You either use Google Oauth and manually enter your credentials everytime, or use a Service Account and forget about further authentications.\n\n### How to create a Service Account\n\n(the following is taken from [google-spreadsheet](https://www.npmjs.com/package/google-spreadsheet) docs)\n\n1. Go to the [Google Developers Console](https://console.developers.google.com/project)\n2. Select your project or create a new one (and then select it)\n3. Enable the Drive API for your project\n\n- In the sidebar on the left, expand **APIs \u0026 auth** \u003e **APIs**\n- Search for \"drive\"\n- Click on \"Drive API\"\n- click the blue \"Enable API\" button\n\n4. Create a service account for your project\n\n- In the sidebar on the left, expand **APIs \u0026 auth** \u003e **Credentials**\n- Click blue \"Add credentials\" button\n- Select the \"Service account\" option\n- Select \"Furnish a new private key\" checkbox\n- Select the \"JSON\" key type option\n- Click blue \"Create\" button\n- your JSON key file is generated and downloaded to your machine (**it is the only copy!**)\n- note your service account's email address (also available in the JSON key file)\n\n5. Share the doc (or docs) with your service account using the email noted above\n\n### Example usage:\n\nLet's say you stored your user credentials in a file called `my_credentials.json`. And you gave permission to the service account's email address over a folder in your Google Drive whose id is `1bibD4HDZVbqOPq882YSDTmZlI06fZvLU`. So you would do:\n\n```js\nconst YOUR_ROOT_FOLDER = '1bibD4HDZVbqOPq882YSDTmZlI06fZvLU',\n\tPATH_TO_CREDENTIALS = path.resolve(`${__dirname}/my_credentials.json`);\n\n// Let's wrap everything in an async function to use await sugar\nasync function ExampleOperations() {\n\tconst creds_service_user = require(PATH_TO_CREDENTIALS);\n\n\tconst googleDriveInstance = new NodeGoogleDrive({\n\t\tROOT_FOLDER: YOUR_ROOT_FOLDER\n\t});\n\n\tlet gdrive = await googleDriveInstance.useServiceAccountAuth(\n\t\tcreds_service_user\n\t);\n\n\t// List Folders under the root folder\n\tlet folderResponse = await googleDriveInstance.listFolders(\n\t\tYOUR_ROOT_FOLDER,\n\t\tnull,\n\t\tfalse\n\t);\n\n\tconsole.log({ folders: folderResponse.folders });\n\n\t// Create a folder under your root folder\n\tlet newFolder = { name: 'folder_example' + Date.now() },\n\t\tcreateFolderResponse = await googleDriveInstance.createFolder(\n\t\t\tYOUR_ROOT_FOLDER,\n\t\t\tnewFolder.name\n\t\t);\n\n\tnewFolder.id = createFolderResponse.id;\n\n\tdebug(`Created folder ${newFolder.name} with id ${newFolder.id}`);\n\n\t// List files under your root folder.\n\tlet listFilesResponse = await googleDriveInstance.listFiles(\n\t\tYOUR_ROOT_FOLDER,\n\t\tnull,\n\t\tfalse\n\t);\n\n\tfor (let file of listFilesResponse.files) {\n\t\tdebug({ file });\n\t}\n}\n\nExampleOperations();\n```\n\nSee [API](API.md) for a description of available methods.\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FHuasoFoundries%2Fnode-google-drive.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FHuasoFoundries%2Fnode-google-drive?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuasofoundries%2Fnode-google-drive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuasofoundries%2Fnode-google-drive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuasofoundries%2Fnode-google-drive/lists"}