Search code examples
javascriptnode.jshttpsgoogle-chrome-devtools

how to monitor the network on node.js similar to chrome/firefox developer tools?


When developing client side javascript applications, the developer network panel is invaluable for debugging network issues:

enter image description here

How does a developer creating a NodeJS application monitor the network traffic from the nodejs application to a http/https server? For example how to debug the following network traffic?

var http = require('http');
var req = http.request ...
req.write ...
req.send()

My code is making a call to a third party https server, so I am unable to use wireshark or similar packet sniffing tools.

For more information, the problem I am trying to investigate is here.

EDIT:

Here are similar questions asking how to do the same thing in other languages:


Solution

  • I know it's not pretty, but you could always output the content of the response headers on the console inside your request call:

    var req = https.request(options, function(res) {
        console.log("statusCode: ", res.statusCode);
        console.log("headers: ", res.headers);
    
        res.on('data', function(d) {
            process.stdout.write(d);
        });
    });
    

    Your original question, however, was not about problems with the server side but rather a problem with the node code itself so this wouldn't be of much use here.