Just Chris


Google Sheets As Your Database

Very rapid prototyping is helpful for trying out your brainstormed ideas while they are still fresh in your mind, without the need for a lot of setup. New tools are emerging which enable you to rapid try out new ideas at the client, server, and database layers.

Tools like GoMix and RunKit can be very helpful in getting your server-side code running quickly, and being able to test out changes on the fly.

In the database layer, a “database” that can be easily edited and used by a server application can be established in minutes using Google Sheets.

In this example, I’ll read from a published Google Sheet. If I need to make changes to the data, I’ll just make them directly in the sheet, so there’s no need to learn a framework. I use gsheet-web for this purpose, which is available on NPM.

Here’s the database. A published public sheet that can be used to store the data.

Reading the sheet data, using the id of the sheet, is very simple.

var gsheet = require('gsheet-web');
gsheet('1KPJr7wBEzicgrqukhEZBdGCqNQQB-ldrRrS0lxmq_qo', (data)=>{
console.log('Try callback ', data.length); // array of objects

In this case, Gsheet-web will read the sheet as an array of objects. Available for your app to use. In this example, since we are not writing to the sheet from the app, there is no authentication required.

Here’s an example of server-side code accessing this data, on RunKit.

It also works with Promises, so will be “async/await ready”. To use the promises interface, simply use:

console.log('Try promise ', data.length);

There are other modules out there that will assist in using G-Sheets data as your database, and dropping these into your prototypes is a fast way to get a database layer up and running without database setup.

Hacker Noon is how hackers start their afternoons. We’re a part of the @AMI family. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.
If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!

More by Just Chris

Topics of interest

More Related Stories