1.0.1 • Published 6 years ago

google-spreadsheets-db v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Google Spreadsheets DB

Get data from Google spreadsheets as Javascript objects using this simple API and take the advantage of having a ready made CMS and readonly data store for your project.

Installation

  • In a browser:
<script src="./dist/google-spreadsheets-db.min.js"></script>
  • Using npm:
$ npm i --save google-spreadsheets-db
  • In Node.js:
const GoogleSpreadsheetsDb = require('google-spreadsheets-db')

Usage

  • DB instance:
const db = new GoogleSpreadsheetsDb(
  'YOUR-API-KEY-HERE',
  'SPREADSHEET-ID-HERE'
)
  • Retrieving all entries of a sheet:
db.getAll('sheet-name', (err, entries) => {
/**
 * entries will be an array of objects
 * the object's keys are the column names of your sheet, ie:
 * [{ name: "First item", description: "some desc." },
 *  { name: "First item", description: "some desc." }]
 */
})

Spreadsheet setup

Table format

Use the first row for column names, like:

idnamedescriptionimages
1First itemsome description goes here"https://somedomain.jpg"
2Second itemsome description goes here"https://somedomain.jpg"

See example

Spreadsheet ID and sheet names

The spreadsheet ID is the value between the "/d/" and the "/edit" in the URL of your spreadsheet. Use it to instanciate GoogleSpreadsheetsDb.

https://docs.google.com/spreadsheets/d/spreadsheetId/edit#gid=0

Setup the sheets names by clicking in the tabs at the bottom of the spreadsheet. By default the first sheet is named Sheet1.

API key and authorization

Follow this wizard in order to generate an API key.

You will also need to update permissions in your spreadsheet:

  1. Click the Share link in the upper right-hand corner
  2. Change access to "On - Anyone with a link"