Skip to content
Discussion options

You must be logged in to vote

Got uses keep-alive by default! The underlying Node.js http/https agents have keepAlive: true enabled automatically.

If you need to customize the agent settings (like keepAliveMsecs or maxSockets), you can pass custom agents:

import http from 'http';
import https from 'https';
import got from 'got';

const httpAgent = new http.Agent({
	keepAlive: true,
	keepAliveMsecs: 30000,
	maxSockets: 50
});

const httpsAgent = new https.Agent({
	keepAlive: true,
	keepAliveMsecs: 30000,
	maxSockets: 50
});

await got('https://example.com', {
	agent: {
		http: httpAgent,
		https: httpsAgent
	}
});

For got-scraping, the same approach should work. The key is that you don't need to manually set keepAlive:…

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