Skip to content
Discussion options

You must be logged in to vote

Yes, you can use the request event which fires when the request is sent:

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 beforeRequest hook if you need to do someting right before the request is sent.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants