Deprecated: Function create_function() is deprecated in /var/www/vhosts/eduardoarellano.com/d4mations.com/wp-content/plugins/wp-automatic/wp-automatic.php on line 70
Google Sheets and JavaScript with Node.js | D4mations.com
  • Saturday , 24 October 2020

Google Sheets and JavaScript with Node.js

Code Canyon



If you’d like to use the data in your Google Sheets projects from your Node applications, this is the guide for you.

We’ll use the google-spreadsheet module (https://www.npmjs.com/package/google-spreadsheet) by Theo Ephraim (https://twitter.com/theozero) to access an example spreadsheet inside of Google Sheets.

Original source

3d Ocean

Related Posts

20 Comments

  1. Twilio
    April 22, 2020 at 07:58

    Got a Google Sheet that you need to access from your code? Let us know if this guide helped you get it done!

  2. Jonathan Li
    April 22, 2020 at 07:58

    How would I protect/encrypt the client_secret.json if I wanted to upload my project to a public GitHub repo? Should I use something like env, gitignore, git-secret?

  3. Justin Harmer
    April 22, 2020 at 07:58

    hi, so for some reason, I tried using this for discord.js, or a node app if you're wondering, and I'm getting this error: TypeError: Cannot set property 'jwtClient' of undefined

  4. Naveen kumar
    April 22, 2020 at 07:58

    I got error of

    UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'jwtClient' of undefined

    at useServiceAccountAuth (C:Usersboopathi.tTrainnigsgoogle-sheets-nodenode_modulesgoogle-spreadsheetlibGoogleSpreadsheet.js:60:20)

    at internal/util.js:278:30

    at new Promise (<anonymous>)

    at useServiceAccountAuth (internal/util.js:277:12)

    at accessSpreadsheet (C:Usersboopathi.tTrainnigsgoogle-sheets-nodespreadsheet.js:8:47)

    at Object.<anonymous> (C:Usersboopathi.tTrainnigsgoogle-sheets-nodespreadsheet.js:14:1)

    at Module._compile (internal/modules/cjs/loader.js:959:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)

    at Module.load (internal/modules/cjs/loader.js:815:32)

    at Function.Module._load (internal/modules/cjs/loader.js:727:14)

  5. Hoàng Mẫn Nguyễn
    April 22, 2020 at 07:58

    const GoogleSpreadsheet = require('google-spreadsheet');
    const doc = new GoogleSpreadsheet('id');
    oogleSpreadsheet is not a constructor

    at accessPreadsheets
    plzz help.

  6. Oussama Khamlichi
    April 22, 2020 at 07:58

    cool Idea, I've been looking for a database solution for sometime now..

  7. Spoot
    April 22, 2020 at 07:58

    Can you make an updated video on v4 google-sheets?

  8. xyras sps
    April 22, 2020 at 07:58

    Thank you for the amazing video. I understand this is a old video but when i'm working on it error pop outs and said googleSpreadsheet is not a constructor is there any way to solve this?

  9. Tiago Ferrero
    April 22, 2020 at 07:58

    Hello, I'm having a problem and that I cannot work around:
    UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'jwtClient' of undefined

    at useServiceAccountAuth (Z:GitHubdiscordBotnode_modulesgoogle-spreadsheetlibGoogleSpreadsheet.js:60:20)

    at internal/util.js:297:30

    at new Promise (<anonymous>)

    at useServiceAccountAuth (internal/util.js:296:12)

    at accessSpreadsheet (Z:GitHubdiscordBotsheetssheets.js:8:45)

    at Object.module.exports.run (Z:GitHubdiscordBotcomandosduvida.js:51:5)

    at Client.<anonymous> (Z:GitHubdiscordBotindex.js:63:21)

    at Client.emit (events.js:311:20)

    at MessageCreateHandler.handle (Z:GitHubdiscordBotnode_modulesdiscord.jssrcclientwebsocketpacketshandlersMessageCreate.js:9:34)

    at WebSocketPacketManager.handle (Z:GitHubdiscordBotnode_modulesdiscord.jssrcclientwebsocketpacketsWebSocketPacketManager.js:105:65)

    I'm trying to get to work on a Discord bot, any ideas to why this is happening?
    Thank you in advance!

  10. BOOPATHI T
    April 22, 2020 at 07:58

    I got error of

    UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'jwtClient' of undefined

    at useServiceAccountAuth (C:Usersboopathi.tTrainnigsgoogle-sheets-nodenode_modulesgoogle-spreadsheetlibGoogleSpreadsheet.js:60:20)

    at internal/util.js:278:30

    at new Promise (<anonymous>)

    at useServiceAccountAuth (internal/util.js:277:12)

    at accessSpreadsheet (C:Usersboopathi.tTrainnigsgoogle-sheets-nodespreadsheet.js:8:47)

    at Object.<anonymous> (C:Usersboopathi.tTrainnigsgoogle-sheets-nodespreadsheet.js:14:1)

    at Module._compile (internal/modules/cjs/loader.js:959:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)

    at Module.load (internal/modules/cjs/loader.js:815:32)

    at Function.Module._load (internal/modules/cjs/loader.js:727:14)

    anyone have solution

  11. Ethan Exabyte
    April 22, 2020 at 07:58

    Hi. i got "Cannot set property 'jwtClient' of undefined" on the " await promisify(doc.useServiceAccountAuth)(creds);" line. Please help

  12. Bhavin Varma
    April 22, 2020 at 07:58

    UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'jwtClient' of undefined

  13. CodeLab
    April 22, 2020 at 07:58

    Excellent Video

  14. Nils Vanhauwaert
    April 22, 2020 at 07:58

    Hi, thanks for this video. Although I think something has changed in Google-Spreadsheet. I'm using the exact same code like you but getting an error back each time.

    This is the code:
    const { GoogleSpreadsheet } = require('google-spreadsheet');

    const { promisify } = require('util');

    const creds = require('./blablabla.json');

    async function accessSpreadsheet() {

    const doc = new GoogleSpreadsheet('xxxxxxxxxxxxxxxxxxxxxxx')

    await promisify(doc.useServiceAccountAuth)(creds)

    const info = await promisify(doc.getInfo)();

    const sheet = info.worksheets[0];

    console.log(`Title: ${sheet.title}, Rows: ${sheet.rowCount}`)

    }

    accessSpreadsheet();

    The error I get back over and over again is:
    (node:5132) UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'jwtClient' of undefined

    at useServiceAccountAuth (C:UsersNilsDesktopnodenode_modulesgoogle-spreadsheetlibGoogleSpreadsheet.js:53:20)

    at internal/util.js:278:30

    at new Promise (<anonymous>)

    at useServiceAccountAuth (internal/util.js:277:12)

    at accessSpreadsheet (C:UsersNilsDesktopnodecryptopremiumsheet.js:8:47)

    at Object.<anonymous> (C:UsersNilsDesktopnodecryptopremiumsheet.js:14:1)

    at Module._compile (internal/modules/cjs/loader.js:956:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)

    at Module.load (internal/modules/cjs/loader.js:812:32)

    at Function.Module._load (internal/modules/cjs/loader.js:724:14)

    (node:5132) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

    (node:5132) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

    Anyone has a solution?

  15. Marcos C. Santos
    April 22, 2020 at 07:58

    TypeError: Cannot set property 'jwtClient' of undefined

  16. Bumblebytrox
    April 22, 2020 at 07:58

    Hi I'm getting this error;
    TypeError: Cannot set property 'jwtClient' of
    undefined

    at useServiceAccountAuth (C:Users*******node_modulesgoogle-spreadsheetlibGoogleSpreadsheet.js:53:20)

  17. Darbayev Nurdaulet
    April 22, 2020 at 07:58

    Hi, i have a problem with spreadsheet.js, when i ran it from console. terminal provides error

  18. Tiago Tozi
    April 22, 2020 at 07:58

    Hii. Thankyou, your video is amazing S2.

    I have a issue when i try to use the code below:
    `————————–
    async function accessSpreadsheet() {

    await promisify (doc.useServiceAccountAuth)(creds);

    const info = await promisify(doc.getInfo)();

    const sheet = info.worksheets[0]; ///busca as informações

    const data = await promisify(sheet.getRows)({
    query: `data = ${datainput}`
    });

    return data.length;

    }

    var total = accessSpreadsheet();

    console.log(total);
    `——————————
    But it return: Promise { <pending> }

    I need to use the value "data.lenght" in another piece of code. What i need to do to use this variable?

  19. Marcelo Lewin
    April 22, 2020 at 07:58

    Amazing. This helped me automate the data from a Google spreadsheet into a JSON file for our internal system to use. Thank you so much!

  20. KnewLight
    April 22, 2020 at 07:58

    Succinct, 👌🏾

    [ viewer subscribed 😎 ]

Leave A Comment

You must be logged in to post a comment.