Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

896
Views
How to connect Google Cloud Bigquery with NodeJS using APIKey

I am trying to insert, delete, search and update in google bigquaey using node js. I have followed up the all documents in google could. But no where its mentioned, how to connect - So I have created this, --

How to connect GCP BigQuery with NodeJS. I am new here. Any help will work.

the code which I have written -

const {BigQuery} = require('@google-cloud/bigquery');

const mainFunction = () => {
    insertIntoBigQuery("John", "john@gmail.com", "+1-23232344231");
}

async function insertIntoBigQuery(name, email, phone) {
// const insertIntoBigQuery = async(name, email, phone) => {
    const bigqueryClient = new BigQuery();
    // The SQL query to run
    const sqlQuery = "INSERT INTO `p4tyu78.Backend_testing.Test1` VALUES ("+name+ "," +email+","+ phone+")";

    const options = {
        query: sqlQuery,
        // Location must match that of the dataset(s) referenced in the query.
        location: 'US',
    };

    // Run the query
    const [rows] = await bigqueryClient.query(options);

    console.log('Rows:');
    rows.forEach(row => console.log(`${row.subject}: ${row.num_duplicates}`));
}

const updateIntoBigQuery = () => {
    
}

const deleteFromBigQuery = () => {
    
}

const searchFromBigQuery = async() => {
    const bigqueryClient = new BigQuery();
    // The SQL query to run
    const sqlQuery = "SELECT * from `p4tyu78.Backend_testing.Test1`";

    const options = {
        query: sqlQuery,
        // Location must match that of the dataset(s) referenced in the query.
        location: 'US',
    };

    // Run the query
    const [rows] = await bigqueryClient.query(options);

    console.log('Rows:');
    rows.forEach(row => console.log(`${row.subject}: ${row.num_duplicates}`));
}

mainFunction();
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Forget the API key, you can't use it for BigQuery (and it's still working with legacy API, but very few). You need to use OAuth2 mechanism to be authenticated.

When you use a Google Cloud API, you need to add an access token in the header of your API request. But in your case, you don't perform directly these API call, you use the client library.

You have a description of the authentication in the documentation. To go quicker, on Google Cloud environment, you can rely on the service service account. In some service you can customize them. You can alse use you own credential, on your computer, and a service account key file on external platform (on prem, on other cloud provider).

So, in your case, you initiate the bigquery library like this const bigqueryClient = new BigQuery();. That means you rely on the environment credential to be connected to BigQuery.

On your environment, to use your own credential, you can use gcloud CLI and run this

gcloud auth application-default login

Login and enjoy!!

But the security is a long way on GCP, it's only the beginning, ask again later if you have difficulties in your choices

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!