The `timed-out` package provides a simple and effective mechanism for adding timeout functionality to Node.js `http.ClientRequest` objects, preventing requests from hanging indefinitely. It automatically emits an `Error` object with specific `code` properties (`ETIMEDOUT` or `ESOCKETTIMEDOUT`) when a request exceeds its defined time limit. The current stable version is `7.0.0`. The project maintains a steady release cadence, typically introducing new major versions to align with Node.js LTS releases and introduce breaking changes like pure ESM adoption. Its key differentiator lies in its focused approach: it specifically extends the native `ClientRequest` object, offering granular control over connection and socket activity timeouts, rather than being part of a larger HTTP client library. This makes it a lightweight solution for augmenting existing `http` and `https` module usage without introducing a full-fledged client.
npm install timed-outVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to apply both simple and granular connect/socket timeouts to Node.js `http.ClientRequest` instances, including proper error and timeout event handling.
Upgrade your Node.js environment to version 20 or higher. Alternatively, use an older version of `timed-out` if you must remain on an earlier Node.js release.
Migrate your project to use ES Modules by setting `"type": "module"` in your `package.json` and using `import` statements. If you require CommonJS, you must use `timed-out@<6.0.0`.
Ensure your Node.js environment is version 12 or newer. For older Node.js, use `timed-out@<6.0.0`.
Update your Node.js environment to version 8 or higher. If backwards compatibility with Node.js <8 is critical, use `timed-out@<5.0.0`.
Convert your project or file to ES Modules by adding `"type": "module"` to your `package.json` or by using `.mjs` file extensions, and then use `import timedOut from 'timed-out';`. If CommonJS is unavoidable, use `timed-out@<6.0.0`.
Ensure you are using the correct default import syntax for ES Modules: `import timedOut from 'timed-out';`.
Ensure you are passing an actual `ClientRequest` instance, typically obtained from `http.get()`, `http.request()`, `https.get()`, or `https.request()`.
Implement robust error handling for `ETIMEDOUT` or `ESOCKETTIMEDOUT` error codes. Consider increasing the timeout duration if the network or server is genuinely slow, or implement retry logic and user notifications.
No dependency data recorded yet.