I am accessing a sheet from which I extract data to put it into a script object globally so I can use it in the rest of the code, however I am not getting the data out of the fetch function even though I am saving it inside the object.
import fetch from 'node-fetch';
const spreadsheet = '...'
var data = {
welcome: '',
q1: '',
}
fetch(sheet)
.then(res => res.text())
.then(text => {
const json = JSON.parse(text.substr(47).slice(0, -2))
data.welcome = json.table.cols[0];
})
console.log(data.welcome)
I got this error:
ReferenceError: json is not defined
at file:///Users/getFAQSheet.js:32:13
at ModuleJob.run (node:internal/modules/esm/module_job:197:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)