Order of execution of API requests in VSCode

Viewed 20

I'm trying to make some API calls in parallel using Promise.all in node.js. I'm getting the correct output as a result. I want to check if my API calls are actually being made in parallel and not in series. Where can I find the order (or rather visualise) in which calls are being made and the response is being received? Are there any tools (VSCode extensions) available to check the same?

1 Answers

Node doesn't include the equivalent of the "Network" tab in dev tools. Some options are

  • Use a debug proxy like mitmproxy
  • Use nock to record requests
  • Instrument your request function

Debug proxy (mitmproxy)

mitmproxy, Burp Suite, Fiddler, Charles will probably suit you more on the visualisation front.

In node, you might need to configure a http agent to proxy requests depending on what http client library is in use.

Some libraries will respect HTTP_PROXY/HTTPS_PROXY set in the environments

nock

Nock has a recorder mode which can print or store all requests/responses

nock.recorder.rec({ output_objects: true, dont_print: true, })

To get the captured array of requests/responses:

const requests = nock.recorder.play()

Code Instrumentation

You could also add the timing data to your request handler

async function get(path) {
  start = Date.now()
  const response = await request(path)
  end = Date.now()
  return {
    start,
    response
    end,
  }
}

For investigation on the other side of the Promise.all.

Related