Got HTTP Client
Got is a human-friendly and powerful HTTP request library for Node.js, currently at v15.0.2. It provides a modern Promise-based API for making HTTP requests, including features like retry mechanisms, hooks, and stream support. The library is actively maintained with frequent patch releases and major version updates that may introduce breaking changes, notably requiring Node.js 22+ and being ESM-only since v12 (reiterated in v15).
Common errors
-
TypeError: promise.cancel is not a function
cause Attempting to call the `cancel()` method on a `got` promise, which was removed in v15.0.0.fixRefactor your cancellation logic to use `AbortController` and the `signal` option: `const controller = new AbortController(); got('url', { signal: controller.signal }); controller.abort();` -
TypeError [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/got/dist/index.js from ... not supported.
cause Trying to import `got` using `require()` in a CommonJS module, but `got` is an ESM-only package.fixConvert your project or the specific file to use ES modules (`import`). Alternatively, use dynamic import: `const got = await import('got');` -
write after end
cause A bug in `got` versions 14.6.0 to 14.6.5 incorrectly auto-closed streams for empty PATCH/DELETE/OPTIONS requests, preventing data from being piped to them.fixUpgrade `got` to version 14.6.6 or higher to resolve the stream auto-end issue for PATCH/DELETE/OPTIONS methods. -
TypeError: Argument for option 'isStream' must be a boolean
cause Using the `isStream` option with a boolean value in `got` v15.0.0+, where this option has been removed.fixRemove the `isStream` option. Instead, use `got.stream()` directly for all streaming use cases.
Warnings
- breaking Got v15.0.0 and later require Node.js 22 or higher.
- breaking The `promise.cancel()` API was removed in v15.0.0.
- breaking The `isStream` option has been removed in v15.0.0.
- gotcha Got is a native ESM package and does not provide a CommonJS export. Attempting to `require()` it will result in an error.
- gotcha The `got` maintainers recommend considering `Ky` (for browser compatibility, smaller size, Fetch API base) or `fetch-extras` (for simpler needs) as alternatives.
Install
-
npm install got -
yarn add got -
pnpm add got
Imports
- got
const got = require('got');import got from 'got';
Quickstart
import got from 'got';
(async () => {
try {
const { data } = await got.post('https://httpbin.org/anything', {
json: {
hello: 'world'
}
}).json();
console.log('Response data:', data);
// Expected output: { "hello": "world" }
} catch (error) {
console.error('Request failed:', error);
}
})();