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

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