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

295
Vistas
How to convert firestore TimeStamp in cloud function or nodejs

hello guys am building a restAPI with express, node and firebase cloud function and it's returning the documents from my collection successfully. But my problem is am returning the date each document was created as JSON but am unable to convert the timestamp date to javascript date..... here is my code for clearity:

// Single report route that accepts a report ID and return the report
app.get('/report/:id', async (req, res) => {
  try {
    let report;
    const reportDoc = await admin.firestore().collection('corruptionReports/').doc(req.params.id).get();
    if (reportDoc.exists) {
      let reportDate = reportDoc.data().createdAt;
      report = {
        id: reportDoc.id,
        createdAt: reportDate.toMillis(),
        ...reportDoc.data()
      }
      return res.status(200).json(report)
    } else {
      return res.status(500).json({
        "status": "failed",
        "message": "invalid report ID"
      })
    }
  } catch (error) {
    return res.status(500).json({
      "status": "failed",
      "message": "invalid report ID"
    })
  }
})

with the code above I basically want to return the document with the server TimeStamp in milliseconds.

about 4 years ago · Juan Pablo Isaza
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