got
16.2.0 · 30 Oct 2026MIT53.2M / weekRepositoryHomepagenpmAtom feed
11.8.6 is the newest release of 11.x.
In short
8 breaking7 new22 fixed
- Breaking
The
options.encodingbehavior has been reverted back to the Got 9 behavior. In other words, the options is only meant for the Got promise API. To set the encoding for streams, simply callstream.setEncoding(encoding). - Breaking
The error name
GotErrorhas been renamed toRequestErrorfor better readability and to comply with the documentation. - Breaking
The
agentoption now accepts only an object withhttp,httpsandhttp2properties. While thehttpandhttpsproperties accept nativehttp(s).Agentinstances, thehttp2property must be an instance ofhttp2wrapper.Agentor be undefined. - Breaking
The
dnsCacheoption is now set to a default instance ofCacheableLookup. It cannot be aMap-like instance anymore. The underlyingcacheable-lookuppackage has received many improvements, for example, it has receivedhostsfile support! Additionally, thecacheAdapteroption has been renamed tocache. Note that it's no longer passed to Keyv, so you need to pass a Keyv instance it if you want to save the data for later. - Breaking
Errors thrown in
inithooks will be converted to instances ofRequestError.RequestErrors provide much more useful information, for example, you can access the Got options (througherror.options), which is very useful when debugging. - Breaking
The options passed in an
inithook may not have aurlproperty. To modify the request URL you should use abeforeRequesthook instead. - Breaking
The
error.requestproperty is no longer aClientRequestinstance. Instead, it gives a Got stream, which provides a set of useful properties. - Breaking
Now requires Node.js 10.19 or later.
Security
1 advisory affects 11.0.0; 11.8.5 fixes them
- ModerateGot allows a redirect to a UNIX socketGHSA-pfrx-2q88-qq97 · 19 Jun 2022Fixed in 11.8.5
Release note
Introducing Got 11! :tada: The last major version was in December last year. :snowflake: Since then, a huge amount of bugs has been fixed. There are also many new features, for example, HTTP2 support is finally live! :globe_with_meridians:
If you find Got useful, you might want to sponsor the Got maintainers.
Breaking changes
Removed support for electron.net
Due to the inconsistencies between the Electron's net module and the Node.js http module, we have decided to officially drop support for it. Therefore, the useElectronNet option has been removed.
You'll still be able to use Got in the Electron main process and in the renderer process through the electron.remote module or if you use Node.js shims.
The Pagination API is now stable
We haven't seen any bugs yet, so please give it a try!
If you want to leave some feedback, you can do it here. Any suggestion is greatly appreciated!
{
- _pagination: {...}
+ pagination: {...}
}API
- Breaking
The
options.encodingbehavior has been reverted back to the Got 9 behavior.
In other words, the options is only meant for the Got promise API.
To set the encoding for streams, simply callstream.setEncoding(encoding).
-got.stream('https://sindresorhus.com', {encoding: 'base64'});
+got.stream('https://sindresorhus.com').setEncoding('base64');
// Promises stay untouched
await got('https://sindresorhus.com', {encoding: 'base64'});- Breaking
The error name
GotErrorhas been renamed toRequestErrorfor better readability and to comply with the documentation.
-const {GotError} = require('got');
+const {RequestError} = require('got');- Breaking
The
agentoption now accepts only an object withhttp,httpsandhttp2properties.
While thehttpandhttpsproperties accept nativehttp(s).Agentinstances, thehttp2property must be an instance ofhttp2wrapper.Agentor be undefined.
{
- agent: new https.Agent({keepAlive: true})
}
{
+ agent: {
+ http: new http.Agent({keepAlive: true}),
+ https: new https.Agent({keepAlive: true}),
+ http2: new http2wrapper.Agent()
+ }
}- Breaking
The
dnsCacheoption is now set to a default instance ofCacheableLookup. It cannot be aMap-like instance anymore. The underlyingcacheable-lookuppackage has received many improvements, for example, it has receivedhostsfile support! Additionally, thecacheAdapteroption has been renamed tocache. Note that it's no longer passed to Keyv, so you need to pass a Keyv instance it if you want to save the data for later.
{
- dnsCache: new CacheableLookup({
- cacheAdapter: new Map()
- })
}
{
+ dnsCache: new CacheableLookup({
+ cache: new Keyv({
+ cacheAdapter: new Map()
+ })
+ })
}
// Default:
{
dnsCache: new CacheableLookup()
}- Breaking
Errors thrown in
inithooks will be converted to instances ofRequestError.RequestErrors provide much more useful information, for example, you can access the Got options (througherror.options), which is very useful when debugging.
const got = require('got');
(async () => {
try {
await got('https://sindresorhus.com', {
hooks: {
init: [
options => {
if (!options.context) {
throw new Error('You need to pass a `context` option');
}
}
]
}
});
} catch (error) {
console.log(`Request failed: ${error.message}`);
console.log('Here are the options:', error.options);
}
})();- Breaking
The options passed in an
inithook may not have aurlproperty. To modify the request URL you should use abeforeRequesthook instead.
{
hooks: {
- init: [
+ beforeRequest: [
options => {
options.url = 'https://sindresorhus.com';
}
]
}
}Note that this example shows a simple use case. In more complicated algorithms, you need to split the init hook into another init hook and a beforeRequest hook.
- Breaking
The
error.requestproperty is no longer aClientRequestinstance. Instead, it gives a Got stream, which provides a set of useful properties.
const got = require('got');
(async () => {
try {
await got('https://sindresorhus.com/notfound');
} catch (error) {
console.log(`Request failed: ${error.message}`);
console.log('Download progress:', error.request.downloadProgress);
}
})();Renamed TypeScript types
Some of the TypeScript types have been renamed to improve the readability:
Old type New type ResponseObject Response Defaults InstanceDefaults DefaultOptions Defaults DefaultRetryOptions RequiredRetryOptions GotOptions Options GotRequestMethod GotRequestFunction
Other
- Breaking
Now requires Node.js 10.19 or later.
Enhancements
HTTP2 support is here! Excited? Yay! Unfortunately, it's off by default to make the migration smoother. Many Got users have set up their own Agents and we didn't want to break them. But fear no more, it will come enabled by default in Got 12.
const got = require('got');
(async () => {
const response = await got('https://nghttp2.org/httpbin/anything', {http2: true});
console.log(response.socket.alpnProtocol);
//=> 'h2'
})();The
mergefunction is slowUse
error.codeinstead oferror.messageto compare errorsPass error thrown in the
inithook tobeforeErrorhookErrors have undefined body when using streams
Spaces should be normalized as
+in query stringsModify response headers while using
got.stream(...)Make
error.requesta Got stream (af0b147).
Known bugs
When some errors occur, the
timingsmay indicate that the request was successful although it failed.When some errors occur, the
downloadProgressobject may show incorrect data.
Bug fixes
Requests to UNIX sockets are missing query strings
beforeRequesthooks aren't called on redirectsErrors are swallowed when using
stream.pipeline(got.stream(...), ...)Cannot use the
cachealong with thebodyoptionGot doesn't throw on leading slashes
Got throws when passing already frozen options
Cannot type Got options properly due to missing types
got.mergeOptions(...)doesn't mergeURLSearchParamsinstancesThe
authorizationheader is leakingPagination should ignore the
resolveBodyOnlyoptionCannot reuse user-provided options
Broken with Node.js ≥ 13.10.0
Cache is not decompressed
beforeRetryhooks are missingoptions.contextpromise.json()doesn't throwParseErrorNot compatible with
tough-cookie@4.0.0Shortcuts give body from the failed request on token renewal
No effect when replacing the
cacheoption in a Got instanceMemory leak when using
cacheGot doesn't throw on aborted requests by the server
All changes
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.