Tips for displaying and sorting two requests within one console

I am currently working on a project to display both folders and subfolders, but only the folders are visible at the moment.

function getParserTypes (types, subject) {
  return types.map((type) => {
    return {
      id: type.entry.id,
      name: type.entry.name,
      grade: subject.grade,
      subject: subject.id
    };
  });
}   

The first request fetches the folders, while the second request retrieves the subfolders.

  const firstRequest = await axios.get(`${fox.url}/nodes/${firstFolderId}/children`, PARAMS);
  const secondRequest = await axios.get(`${fox.url}/nodes/${secondFolderId}/children`, PARAMS);


 const types = _(firstRequest.data.list.entries).filter((type) => !type.entry.name.includes('dog'),
      secondRequest.data.list.entries).filter((type) => !type.entry.name.includes('cat');
    
      const resourcesTypes = getParserTypes(types, subject);
    
      
      console.log("resourcesTypes",resourcesTypes)

However, only the information from my first request is displayed in the console, not from both requests.

https://i.stack.imgur.com/xZcrA.png

Answer â„–1

You haven't received responses for both requests yet. As these are Promises, you have the option to use Promise.all or Promise.allSettled. For more details, check out this discussion. Both methods return a Promise.

  const res1 = await axios.get(
    "https://jsonplaceholder.typicode.com/todos/1"
  );
  const res2 = await axios.get(
    "https://jsonplaceholder.typicode.com/todos/2"
  );
  const res = await Promise.all([res1, res2]);
  console.log(res);
  -------- or --------------
  Promise.all([res1, res2]).then((res) => {
      console.log(res);
  })

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

NodeJs - routing parameters causing file system crash for users

This is my unique server const path = require('path'); const express = require('express'); const exphbs = require('express-handlebars'); const bodyParser = require('body-parser'); const handlebars = exphbs.create( ...

Error: The function was expecting a mapDiv with the type of Element, but instead undefined was passed - google

I have a map within a div tagged with #mapa. Whenever I try to plot a route on the map, it refreshes. I don't want the map to refresh, and here is the code I currently have: <div style="height: 500px; width: auto;" #mapa> <google-map heigh ...

The Node.js encountered an error, stating that it cannot locate the module named 'bluebird'

Running the command "hexo generate" results in an error stating that the module 'bluebird' cannot be found. Any ideas on how to resolve this issue? $ hexo generate ERROR Error: Cannot find module 'bluebird' at Function.Module._reso ...

Using Paper.js to access and manipulate document.body.style.opacity within a paperscript

My website is essentially one large canvas image. Currently, the body fades in when loaded using this code: <body onLoad="document.body.style.opacity='1'"> However, I want to initiate this fade within my paperscript because sometimes the ...

Develop a personalized API using Strapi that involves integrating data from two distinct tables

I am relatively new to Strapi, so please forgive my lack of experience. My goal is to set up a custom route for retrieving complex data using two related tables. I have relationships with the "items" and "comments" tables. My approach involves selecting ...

Challenges arise when trying to access environment variables using react-native-dotenv in React

I am currently working on two separate projects, one being an app and the other a webapp. The app project is already set up with react-native-dotenv and is functioning as expected. However, when I attempt to use the same code for the webapp, I encounter an ...

Is there a way to stop the Firebase web client from altering the error message generated by an https.onRequest function?

I am facing an issue where I cannot retrieve the original message I sent from an "https.onRequest" function in Firebase. The firebase client is rewriting the message based on the error code, making it difficult for me to recover the originally sent body or ...

Managing React state fields utilizing an array of objects

I am struggling to integrate this with my React state. The current setup is functional and allows me to access the necessary data, but I aim to enhance the 'questions' field so that it becomes an array of objects instead of a single object. this. ...

The issue arises when FormData is sending a request with no content when attempting to transfer

I am attempting to use FormData and Axios to send a form, but I am encountering issues. const formData = new FormData(); formData.append("title", title); formData.append("image", image); Axios.post("https://httpbin.org/anything&quo ...

Is there a way to rotate the custom marker icon in vue2-google-map?

After reading the documentation, I discovered that using path is the only way to rotate the marker. In an attempt to customize my marker, I created my own PNG image. However, I have been unsuccessful in overriding the CSS of the marker. I even tried to ov ...

Develop a Route in ExpressJS without the need to register the Routing Module

To set up routing in ExpressJS, you typically include the following code: app.use(app.router); When defining a route, it looks something like this: app.get('/user/:id', function(req, res){ ... }); A common issue arises when a route is defin ...

Loading handlebar templates for sending emails with nodemailer from a remote server is simple and straightforward

I currently have a nestjs application with a POST /email endpoint that utilizes nodemailer to send emails based on handlebar templates. The template used depends on the selection made in the API call (template=xxx). For example, http://localhost:3000/< ...

Using a PNG image served from a Node.js server presents challenges when trying to use it as a marker in an Ionic

Currently, all of my images are being loaded from the server URL. This is how it looks in HTML: <img [src]="http://myserverurl.../image.png" /> Everything is working fine and I can see the images on the profiles. However, I am also using t ...

Fatal error: zoid has obliterated all components inreactjs nextjs

I recently integrated PayPal into my Next.js application. Everything loads fine when I first visit the page, but if I navigate away and then back, it throws an error: unhandled_error: zoid destroyed all components↵ Unfortunately, PayPal does not provid ...

The procedure for deleting npm and node package on a Mac system

Currently, I am struggling to completely remove the npm and node packages that I initially installed in order to replace them with the Homebrew version. Can someone provide me with guidance on how to successfully eliminate the package versions of node.js a ...

Merge two separate mongodb records

Just getting started with javascript / express / mongodb. For my initial project, I am working on a simple task manager where todos are categorized by priority - "high," "mid," or "low." However, I am facing an issue when trying to display different entri ...

Using Styled Components to achieve full width for input tag in relation to its parent

I am working with an input field that has a specific width set. My goal is to increase the width of this input field to 100% by selecting it from its parent component. Is there a way to achieve this without passing an explicit width prop in the styled c ...

Tips for initializing a jstree with no content?

When I click a button, I send a key to the controller and retrieve my lists using JSON. The array inside my lists serves as my children in my jstree. $("#btnSearch").on("click", function () { alert("I'm also here"); $.ajax({ ...

What is the best way to link a newly created contact to the current user in Mongoose?

I'm faced with the challenge of creating a contact that is specifically added to the current user's contact array. Currently, my controller only creates a generic contact and doesn't cater to the individual user. Controller: function cont ...

How to Send a PDF Attachment using Node.js and SendGrid

For my Node.js application, I have been utilizing SendGrid to send emails. However, every time I attempt to attach a pdf file, the attached pdf ends up being unreadable. I have attempted the following: fs.readFile('public_html/img/Report.pdf',fu ...