Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

899
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda