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

150
Visualizações
How to initialize Firebase V9 database in Node

I think I'm getting confused between firebase-admin and Web SDK I simply would like to connect a scheduled job that will push data into my Real-time database

Project structure

enter image description here

Package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "14"
  },
  "main": "index.js",
  "dependencies": {
    "firebase-admin": "^9.8.0",
    "firebase-functions": "^3.14.1"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}

How can I correctly connect my scheduled cloud function to Firebase Database?

Here is my index.js where most scheduled functions will live

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const serviceAccount = require("./serviceAccountKey.json");
//const { push } = require("firebase/database")

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "myurl"
});

const database = admin.database();

exports.scheduledFunction = functions.pubsub
  .schedule("every 1 minutes")
  .onRun((context) => {
    push(database, "/hello", {
        message: "world"
    })
    return console.log("This will be run every 1 minutes!");
  });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The Admin SDK is not totally modular like the client SDK yet so you'll have to use the namespaced syntax if using the Admin SDK:

const db = admin.database();

exports.scheduledFunction = functions.pubsub
  .schedule("every 1 minutes")
  .onRun((context) => {
    console.log("This will be run every 1 minutes!");
 
    return db.ref('hello').push({ name: "Hellow" });
  });
about 4 years ago · Juan Pablo Isaza 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