Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

332
Vistas
Get document data from Firebase Firestore in Node JS

after not finding anything online, I decided to write here. I need to get all the document in the /user/uid collection in Node JS. When I use the Firebase code it replies like this:

Promise {<pending>}

Please help me!

PS: I don't want to use Firebase Admin SDK and await.

"Full" code

var express = require('express');

const { initializeApp } = require("firebase/app");
const { getDatabase, ref, get, child, set, onValue} = require("firebase/database");
const { getFirestore, collection, getDoc, doc} = require("firebase/firestore");

const firebaseApp = initializeApp(firebaseConfig);

// Get a reference to the database service

var app = express();

const PORT = process.env.PORT || 5050

app.get('/', (req, res) => {
    res.send('This is my demo project')
});

const db = getDatabase();
const firestore = getFirestore();


const document = getDoc(doc(collection(firestore, 'users'), "BW5kylV6rtZXtYibpKGc2m1asRm1"));
  
console.log(document);

//Response: "Promise {<pending>}""
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Firebase method calls are asynchronous. So for both the Admin SDK or the JS SDK you have to deal with the asynchronicity, either by using then or by using async/await.

If you receive Promise {<pending>} it is because the asynchronous method getDoc returns a Promise and this promise is not fulfilled, but is still pending.

So you need to dive into the documentation on how to use Promises... or the async/await keywords.

In your case, the following will do the trick:

getDoc(doc(collection(firestore, 'users'), "BW5kylV6rtZXtYibpKGc2m1asRm1"))
.then(snap => {
   console.log(snap.data())
})

However, if you write this code for running on a Node server you own, I would recommend to use the Admin SDK.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda