request wraps the http module so you can use the 'socket' event emitted by the request object to listen for net.Socket events.
Based on your question you can listen for the'lookup', 'connect', 'data' and 'close' events on the Socket and use console.time() and console.timeEnd() to keep track of the time taken for the operation.
// You can use request from npm
const request = require('request')
// Or the native http/https module
// const {request} = require('https')
// Store the http.ClientRequest object returned
const req = request('https://www.google.com')
// Listen for the 'socket' event and then attach listeners to the socket
req.on('socket', socket => {
console.time('dnsInfo')
socket.once('lookup', (err, address, family, host) => {
console.timeEnd('dnsInfo')
console.log(address, family, host)
})
socket.once('connect', () => {
console.time('requestTime')
console.time('initialData')
console.log('Connected to server')
})
socket.once('data', chunk => console.timeEnd('initialData'))
socket.once('close', () => console.timeEnd('requestTime'))
})
req.end()