sheets-database is a JavaScript/TypeScript library designed to enable developers to use Google Sheets as a lightweight, no-cost database or content management system. Currently at version 1.0.4, it provides a simple and intuitive API for common database operations like creating, reading, updating, and deleting (CRUD) tables and their entries. The library offers multiple authentication methods, including Service Account, OAuth, Access Token, and API Key, and includes features to optimize memory and network usage for suitable use cases. While it handles internal synchronization with Google Sheets, it is explicitly positioned for small applications and datasets, warning against its use for applications with many entries or complex joins where traditional databases are more appropriate. Release cadence appears to be minor patches within the 1.0.x range, indicating stability and ongoing maintenance.
npm install sheets-databaseVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes a SheetDatabase instance, authenticates using a Google Service Account (best practice for backend), synchronizes with the sheet, adds a new table, inserts and updates data, and demonstrates renaming a table. It includes robust environment variable handling for credentials.
Wrap top-level `await` calls in an `async` function and invoke it, or configure your project for ES Modules and ensure your script is treated as such.
Evaluate your application's data scale and query complexity. For larger datasets or relational needs, consider a dedicated database solution (e.g., PostgreSQL, MongoDB).
Share your Google Sheet with the `client_email` of your Service Account, granting editor access. Verify the Service Account JSON keys are correctly configured and accessible to your application.
Implement rate limiting or exponential backoff in your application logic for operations that might trigger high API usage. Optimize data fetching to retrieve only necessary data and batch writes where possible.
Double-check your `GOOGLE_SERVICE_ACCOUNT_EMAIL` and `GOOGLE_PRIVATE_KEY` environment variables. Ensure the private key correctly handles newline characters (e.g., replace `\n` with `\n`). Regenerate credentials if necessary.
Verify the `GOOGLE_SHEET_ID` environmental variable or literal string matches the ID from the Google Sheet URL. Confirm the authenticated Google account (Service Account or OAuth) has at least read access to the sheet.
Wrap all `await` calls within an `async` function, or configure your Node.js project to use ES Modules by adding `"type": "module"` to your `package.json` file and using `.mjs` or `.js` files when appropriate.
Share the Google Sheet directly with the email address of your Service Account or the Google account used for OAuth, granting appropriate permissions (e.g., Editor for write access).
No dependency data recorded yet.