This, pretty much:
server.get("/api/photos", async (req, res) => { const days = req.query.days const dates = generateDates(days) const requests = dates.map((date) => axios.get(`${URL}?api_key=${api_key}&date=${date}`)); try { const result = await Promise.all(requests); res.status(200).json({ items: requests.length, photos: result.map(item => item.data) }); } catch (err) { res.status(500).json({ error: String(err) }); } })
There's also Promise.allSettled if you want all of the results, error or not.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This, pretty much:
There's also Promise.allSettled if you want all of the results, error or not.