简体   繁体   中英

How can I integrate a credential json file with GCP bigquery with nodejs?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM