0

I'm using google spreadsheet and when I use process.exit() to stop my script It doesn't save the changes that I made to the spreadsheet. The problem is in the "row.save()" part, row.id row.status and row.tr_link do update. If I take out the process.exit() everything works fine.

 async function accessSpreadsheet() {
    const document = new GoogleSpreadsheet(thespreadsheetkey)
    await promisify(document.useServiceAccountAuth)(credentials)
    const info = await promisify(document.getInfo)()
    const sheet = info.worksheets[0]

    const rows = await promisify(sheet.getRows)()
    var counter = 0
    rows.forEach(async (row) => {
        if (row.status == "") {
            let data = await getCompanyID(row.email)
            if (!data) {
                await createCompany(row)
                console.log(
                    `...`
                )
                //sendEmail(company)
            } else
                console.error(
                    `...`
                )
            row.status = "sent"
            row.save()
        } else if (row.status == "sent" && row.id == "") {
            let data = await getCompanyID(row.email)
            if (!data) {
                console.error(
                    `...`
                )
            }
            try {
                row.id = data.id
                row.tr_link = `...`
                row.save()
                console.log(
                    `...`
                )
            } catch (err) {
                console.error(err, err.stack)
            }
        }
        counter++
        if (counter == rows.length) {
            console.log("...")
            return process.exit(0)
        }
    })
}
Nik
  • 11
  • 1

0 Answers0