Gathering detailed insights and metrics for node-abort-controller
Gathering detailed insights and metrics for node-abort-controller
Gathering detailed insights and metrics for node-abort-controller
Gathering detailed insights and metrics for node-abort-controller
@smithy/abort-controller
A simple abort controller library
abort-controller
An implementation of WHATWG AbortController interface.
@azure/abort-controller
Microsoft Azure SDK for JavaScript - Aborter
native-abort-controller
Returns native AbortController/AbortSignal if available or the abort-controller module if not
AbortController Polyfill for Node.JS based on EventEmitter
npm install node-abort-controller
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
54 Stars
75 Commits
14 Forks
2 Watching
2 Branches
10 Contributors
Updated on 06 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-8.5%
2,064,007
Compared to previous day
Last week
1.5%
11,909,653
Compared to previous week
Last month
5.2%
50,197,637
Compared to previous month
Last year
84.5%
495,550,044
Compared to previous year
3
AbortController Polyfill for Node.JS based on EventEmitter for Node v14.6.x and below.
Are you using Node 14.7.0 or above? You don't need this! Node has AbortController
and AbortSignal
as builtin globals. In Node versions >=14.7.0 and <15.4.0 you can access the experimental implementation using --experimental-abortcontroller
.
fetch
1import fetch from "node-fetch"; 2import { AbortController } from "node-abort-controller"; 3 4const controller = new AbortController(); 5const signal = controller.signal; 6 7await fetch("https:/www.google.com", { signal }); 8 9// Abort fetch after 500ms. Effectively a timeout 10setTimeout(() => controller.abort(), 500);
fetch
function with a built in timeout1import { AbortController } from "node-abort-controller"; 2import fetch from "node-fetch"; 3 4const fetchWithTimeout = async (url = "") => { 5 const controller = new AbortController(); 6 const { signal } = controller; 7 8 const timeout = setTimeout(() => { 9 controller.abort(); 10 }, 5000); 11 12 const request = await fetch(url, { signal }); 13 14 clearTimeout(timeout); 15 16 const result = await req.json(); 17 18 return result; 19};
You might not need to! Generally speaking, there are three environments your JavaScript code can run in:
For modern JS APIs, each environment would ideally get a polyfill:
In practice, this is hard. Tooling such as webpack and browserify are great at making sure stuff works out of the box in all environments. But it is quite easy to fail on both points above. In all likelyhood, you end up shipping less than ideal polyfills on platforms that don't even need them. So what is a developer to do? In the case of fetch
and AbortController
I've done the work for you. This is a guide to that work.
If you are building a ...
You don't need this library! AbortController
is now built into nodeJS . Use that instead.
You don't need a library! Close this tab. Uninstall this package.
Use this package and node-fetch. It is minimally what you need.
Use abort-controller and whatwg-fetch. These are more complete polyfills that will work in all browser environments.
Use abort-controller and cross-fetch. Same as above, except cross-fetch will polyfill correctly in both the browser and node.js
fetch
internallyUse this package and node-fetch. It is the smallest and least opinionated combination for your end users. Application developers targeting Internet Exploer will need to polyfill AbortController
and fetch
on their own. But your library won't be forcing unecessary polyfills on developers who only target modern browsers.
With the above guide in mind, this library has a very specific set of goals:
This is the ideal for library authors who use fetch
and AbortController
internally and target both browser and node developers.
Thank you @mysticatea for https://github.com/mysticatea/abort-controller. It is a fantastic AbortController
polyfill and ideal for many use cases.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 7/20 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
12 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More