{"id":13516400,"url":"https://github.com/franciscop/drive-db","last_synced_at":"2025-09-27T13:30:29.064Z","repository":{"id":26031393,"uuid":"29474407","full_name":"franciscop/drive-db","owner":"franciscop","description":":bar_chart: Use Google Drive spreadsheets as a simple database","archived":true,"fork":false,"pushed_at":"2021-09-18T14:08:25.000Z","size":131,"stargazers_count":826,"open_issues_count":0,"forks_count":41,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-09-27T00:20:17.036Z","etag":null,"topics":["database","db","drive","google-drive","sheet","spreadsheet"],"latest_commit_sha":null,"homepage":"","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/franciscop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"custom":"https://www.paypal.me/franciscopresencia/19"}},"created_at":"2015-01-19T14:25:00.000Z","updated_at":"2024-08-11T17:16:05.000Z","dependencies_parsed_at":"2022-08-26T13:41:51.131Z","dependency_job_id":null,"html_url":"https://github.com/franciscop/drive-db","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/franciscop%2Fdrive-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/franciscop%2Fdrive-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/franciscop%2Fdrive-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/franciscop%2Fdrive-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/franciscop","download_url":"https://codeload.github.com/franciscop/drive-db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234438023,"owners_count":18832606,"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":["database","db","drive","google-drive","sheet","spreadsheet"],"created_at":"2024-08-01T05:01:21.977Z","updated_at":"2025-09-27T13:30:28.748Z","avatar_url":"https://github.com/franciscop.png","language":"JavaScript","funding_links":["https://www.paypal.me/franciscopresencia/19"],"categories":["JavaScript","JavaScript (71)"],"sub_categories":[],"readme":"# drive-db [![npm install drive-db](https://img.shields.io/badge/npm%20install-drive--db-blue.svg)](https://www.npmjs.com/package/drive-db) [![test badge](https://github.com/franciscop/drive-db/workflows/tests/badge.svg)](https://github.com/franciscop/drive-db/blob/master/index.test.js) [![demo](https://img.shields.io/badge/demo-blue.svg)](https://jsfiddle.net/franciscop/1w4t7mc5/)\n\n\u003e NOTICE: **Google has killed Google Sheets API v3 that allowed this library to exist**. So unfortunately this library no longer works. Their new API **does not** provide the same functionality and it doesn't allow you to publish a spreadshit, so we cannot do anything on our end.\n\u003e\n\u003e If you depended on this library for anything important, we are very sorry. The new Sheets v4 does work with you creating a whole backend-frontend OAuth workflow (which is what this library was designed to avoid), so please use other libraries out there that allow for this.\n\u003e\n\u003e Thank you so much everyone for using this library for as long as you have and the feedback and love sent. It is one of the first and favorite libraries I've ever made, and it has powered all sort of things AFAIK, from blog posts, public charts, Covid19 panels, etc. So it is with a heavy heart that I have to write this notice, deprecating `drive-db`.\n\nUse Google Drive spreadsheets as a simple database for Node.js and the browser. Perfect for collaboration with multiple people editing the same spreadsheet:\n\n```js\nimport drive from 'drive-db';\n\n// Load the data from the Drive Spreadsheet\n(async () =\u003e {\n  const db = await drive(\"1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k\");\n  console.log(db);\n})();\n```\n\n| id | firstname | lastname | age | city          |\n|----|-----------|----------|-----|---------------|\n| 1  | John      | Smith    | 34  | San Francisco |\n| 2  | Merry     | Johnson  | 19  | Tokyo         |\n| 3  | Peter     | Williams | 45  | London        |\n\nBecomes an array of objects with the corresponding keys:\n\n```json\n[\n  {\n    \"id\": \"1\",\n    \"firstname\": \"John\",\n    \"lastname\": \"Smith\",\n    \"age\": \"34\",\n    \"city\": \"San Francisco\"\n  },\n  {\n    \"id\": \"2\",\n    \"firstname\": \"Merry\",\n    \"lastname\": \"Johnson\",\n    \"age\": \"19\",\n    \"city\": \"Tokyo\"\n  },\n  ...\n]\n```\n\n\n\n## Getting Started\n\nCreate the Google Drive spreadsheet and **publish it**:\n\n- Create [a Google Spreadsheet](https://www.google.com/sheets/about/)\n- File \u003e Publish to the Web \u003e Publish\n- Copy the id between `/spreadsheets/` and `/edit` in the url:\n\n    \u003e [https://docs.google.com/spreadsheets/d/\u003cstrong\u003e1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k\u003c/strong\u003e/edit](https://docs.google.com/spreadsheets/d/1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k/edit)\n\nNow you can either add the CDN `\u003cscript\u003e` or use a bundler. For the CDN:\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/drive-db\"\u003e\u003c/script\u003e\n```\n\nOtherwise install `drive-db` in your project:\n\n```bash\nnpm install drive-db\n```\n\nAnd then load the spreadsheet into your project:\n\n```js\n// Include the module and tell it which spreadsheet to use\nconst drive = require(\"drive-db\");\n\n// Create an async context to be able to call `await`\n(async () =\u003e {\n  // Load the data from the Drive Spreadsheet\n  const db = await drive(\"1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k\");\n\n  console.log(db);\n})();\n```\n\nThe table has to have a structure similar to this, where the first row are the alphanumeric field names:\n\n| id | firstname | lastname | age | city          |\n|----|-----------|----------|-----|---------------|\n| 1  | John      | Smith    | 34  | San Francisco |\n| 2  | Merry     | Johnson  | 19  | Tokyo         |\n| 3  | Peter     | Williams | 45  | London        |\n\nSee [this document](https://docs.google.com/spreadsheets/d/1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k/edit#gid=0) as an example. **Please do not request access to edit it**.\n\n\n\n## API\n\nYou import a single default export depending on your configuration:\n\n```js\n// For ES7 modules\nimport drive from \"drive-db\";\n\n// For common.js imports\nconst drive = require(\"drive-db\");\n```\n\nTo retrieve the data call it and await for the promise it returns:\n\n```js\n// With async/await:\nconst db = await drive(SHEET_ID);\nconst db = await drive(options);\nconsole.log(db);\n\n// Use the callback syntax:\ndrive(SHEET_ID).then(db =\u003e console.log(db));\ndrive(options).then(db =\u003e console.log(db));\n```\n\n**SHEET_ID**: alias of `options = { sheet: SHEET_ID }`:\n\n```js\nconst db = await drive(\"1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k\");\nconsole.log(db);\n```\n\n**options**: a simple object containing some options:\n\n```js\nconst db = await drive({\n  sheet: \"1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k\",\n  tab: \"1\",\n  cache: 3600\n});\n```\n\n- `sheet` (required): when editing a google spreadsheet, it's the part between `/spreadsheets/` and `/edit` in the url. Please make sure to also publish the spreadsheet before copying it (File \u003e Publish to the Web \u003e Publish)\n- `tab` (`\"1\"`): the tab to use in the spreadsheet, which defaults to the first tab. It's the number *as a string* of the tab. See [this demo](https://jsfiddle.net/franciscop/oj0fg9n6/) as an example of how to load the second tab.\n- `cache` (`3600`): set the maximum time (in **seconds**) that the current cache is valid. After this, the data will be loaded again when the function is called. This is really useful when combined with development env constant. Set to 0 to refresh in each request.\n\nIt returns a plain Javascript array. With ES6+, operations on arrays are great, but feel free to use Lodash or similar if you want some more advanced queries.\n\nIf you are using [server for Node.js](https://serverjs.io/) with ES6+:\n\n```js\nconst drive = require(\"drive-db\");\nconst sheet = \"1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k\"; // Or from .env\n\nconst server = require(\"server\");\nconst { get } = server.router;\nconst { render } = server.reply;\n\nconst home = get(\"/\", async ctx =\u003e {\n  const records = await drive(sheet);\n  return render(\"index\", { records });\n});\n\nserver(home);\n```\n\n## Advanced\n\nThere are some more advanced things that you might consider. While I recommend you to read the code for this, here are a couple of examples.\n\n\n### Warm the cache\n\nTo warm the cache on project launch before the first request comes in, call the promise without awaiting or doing anything with it:\n\n```js\nconst drive = require(\"drive-db\");\nconst sheet = \"1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k\";\n// Warms the cache as soon as the Node.js project is launched\ndrive(sheet);\n\nconst server = require(\"server\");\nconst { get } = server.router;\nconst { render } = server.reply;\n\nconst home = get(\"/\", async ctx =\u003e {\n  // Cache is already warm when this request happens\n  const records = await drive(sheet);\n  return render(\"index\", { records });\n});\n\nserver(home);\n```\n\n\n### Refresh the cache\n\nTo force-refresh the cache at any point you can call `drive()` with a cache time of 0:\n\n```js\ndrive({ sheet, cache: 0 });\n```\n\n### Load locally\n\nThis is not available anymore. Since `drive-db` returns a plain array, you can just load the data locally:\n\n```js\nconst data = require(\"./data.json\");\n```\n\n\n\n## Thanks to\n\n- [Creating and publishing a node.js module](https://quickleft.com/blog/creating-and-publishing-a-node-js-module/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffranciscop%2Fdrive-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffranciscop%2Fdrive-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffranciscop%2Fdrive-db/lists"}