Skip to content

Instantly share code, notes, and snippets.

@PaulieScanlon
Created June 16, 2024 14:29
Show Gist options
  • Save PaulieScanlon/6cef226dc0b81f40e3290252b02e4fe5 to your computer and use it in GitHub Desktop.
Save PaulieScanlon/6cef226dc0b81f40e3290252b02e4fe5 to your computer and use it in GitHub Desktop.
Google Sheet service
// ./services/google-spreadsheet.ts
import { GoogleSpreadsheet } from 'google-spreadsheet';
import { JWT } from 'google-auth-library';
const serviceAccountAuth = new JWT({
email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
key: process.env.GOOGLE_PRIVATE_KEY.split(String.raw`\n`).join('\n'),
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
});
export const doc = new GoogleSpreadsheet(process.env.GOOGLE_SHEET_ID, serviceAccountAuth);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment