Request sent event #2382
-
|
Is there a way to subscribe on event: "the request is sent"? |
Beta Was this translation helpful? Give feedback.
Answered by
sindresorhus
Oct 11, 2025
Replies: 1 comment
-
|
Yes, you can use the const request = got('https://example.com');
request.on('request', (request) => {
console.log('Request sent:', request.requestUrl);
});
const response = await request;Keep in mind the request object passed to the event is the underlying Node.js request (http.ClientRequest), so you can access things like headers, method, etc. from it. Alternatively, you could use the |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sindresorhus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, you can use the
requestevent which fires when the request is sent:Keep in mind the request object passed to the event is the underlying Node.js request (http.ClientRequest), so you can access things like headers, method, etc. from it.
Alternatively, you could use the
beforeRequesthook if you need to do someting right before the request is sent.