1.0.4 • Published 10 months ago
google-sheet-to-csv v1.0.4
Google Sheet To CSV
Use Google service accounts to download a Google Sheet locally as a csv
Getting started
Install the Library
npm i google-sheet-to-csv
Google Cloud Setup
- Create a new project
- Save the project id
- Create a service account
- Set the role as
viewer
- Save the unique id
- Set the role as
- Create credentials for service account
- Share google sheet with service account
- Service account email will resemble something along the lines of
[projectName]@[projectId].iam.gserviceaccount.com
- Set the role as
viewer
- Service account email will resemble something along the lines of
Authorization
There are 2 authorization strategies: credentials.json or ENV variables.
Credentials.json
Move the JSON file to the [rootDir]/tokens
directory. If storing in a different location, update the keyFile
option.
ENV variables
There are 4 required env variables:
GOOGLE_PROJECT_ID
: Defined when creating a project
GOOGLE_CLIENT_ID
: Unique id of service account
GOOGLE_PRIVATE_KEY_ID
: Included in credentials.json
GOOGLE_PRIVATE_KEY
: Included in credentials.json
And one optional env variable:
GOOGLE_PROJECT_NAME
: Defined when creating a project
If this is not included, it's extracted from the project id.
Params
name | description | type | required | default value |
---|---|---|---|---|
fileId | id of the Google sheet | string | true | n/a |
keyFile | Filepath of the JSON file for service account credentials. Relative to root directory. If JSON file doesn't exist, it will be created. | string | false | "rootDir/tokens/credentials.json" |
outputFile | Filepath of the outputted CSV file. Relative to root directory | string | false | "rootDir/assets/output.csv" |
verbose | Whether to display logs or not | boolean | false | false |