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

146
Views
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 answers
Answer question

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 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!