Reputation: 59
I have a file type of json. It is a credential file. I want to integrate with GCP bigquery
and access to GCP bigquery
using this credential file with Nodejs.
How can I do that?
How can integrate with GCP bigquery
using credential file in nodejs?
How can I test the result of integration to test integration is valid or not?
Upvotes: 0
Views: 1510
Reputation: 1524
You probably want the keyFilename
attribute, unless I've misunderstood your question.
This GCP doc talks about authenticating using a service account key file.
So if your credentials file lived in /var/my_credentials.json
(dumb path but whatever), your Node.js code would look something like this:
const {BigQuery} = require('@google-cloud/bigquery');
const options = {
keyFilename: '/var/my_credentials.json',
projectId: 'my_project',
};
const bigquery = new BigQuery(options);
Also consider: keep the contents of that credentials file in Google Secret Manager and use gcloud secrets versions access latest
, dumping the output into a temporary json file local to the script, then remove the temporary json file after it's no longer needed by the script. No need to have credentials floating around on servers.
Upvotes: 2