DEV Community


Discussion on: Making concurrent API calls in Node

ironydelerium profile image

This, pretty much:

server.get("/api/photos", async (req, res) => {
  const days = req.query.days
  const dates = generateDates(days)

  const requests = => axios.get(`${URL}?api_key=${api_key}&date=${date}`));

  try {
    const result = await Promise.all(requests);
    res.status(200).json({ items: requests.length, photos: => });
  } catch (err) {
    res.status(500).json({ error: String(err) });
Enter fullscreen mode Exit fullscreen mode

There's also Promise.allSettled if you want all of the results, error or not.