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

后端 未结 5 1878
猫巷女王i
猫巷女王i 2021-01-31 02:05

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

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-31 02:43

    If you only need to see URLs of outgoing traffic and what caused it, You can use debugging-aid

    npm i -D debugging-aid
    node --require debugging-aid/network app.js 
    

    Resulting console output may look like this:

    [aid] network, outgoing  to: http://example.com/
     stack:     at Agent.createSocket (_http_agent.js:234:26)
        at Agent.addRequest (_http_agent.js:193:10)
        at new ClientRequest (_http_client.js:277:16)
        at Object.request (http.js:44:10)
        at Request.start (myapp-path/node_modules/request/request.js:751:32)
        at Request.end (myapp-path/node_modules/request/request.js:1511:10)
    [aid] network, outgoing  to: http://example.com/
     stack:     at Agent.createSocket (_http_agent.js:234:26)
        at Agent.addRequest (_http_agent.js:193:10)
        at new ClientRequest (_http_client.js:277:16)
        at Object.request (http.js:44:10)
        at get (myapp-path/node_modules/got/source/request-as-event-emitter.js:234:22)
        at Immediate. (myapp-path/node_modules/got/source/request-as-event-emitter.js:305:10)
    

    Disclaimer:

    I'm the author of debugging-aid
    This answer was written when debugging-aid was on version 0.2.1

提交回复
热议问题