Gathering detailed insights and metrics for cross-fetch
Gathering detailed insights and metrics for cross-fetch
Gathering detailed insights and metrics for cross-fetch
Gathering detailed insights and metrics for cross-fetch
cross-undici-fetch
Cross Platform Smart Fetch Ponyfill
@whatwg-node/fetch
Cross Platform Smart Fetch Ponyfill
response-iterator
Creates an async iterator for a variety of inputs in the browser and node. Supports fetch, node-fetch, and cross-fetch
@d-fischer/cross-fetch
Universal WHATWG Fetch API for Node, Browsers and React Native
Universal WHATWG Fetch API for Node, Browsers and React Native.
npm install cross-fetch
Typescript
Module System
Node Version
NPM Version
98.1
Supply Chain
99
Quality
78
Maintenance
100
Vulnerability
100
License
JavaScript (52.53%)
TypeScript (30.92%)
HTML (8.39%)
Shell (4.09%)
Makefile (4.07%)
Total Downloads
2,930,916,332
Last Day
964,530
Last Week
18,521,016
Last Month
80,756,391
Last Year
859,184,238
MIT License
1,687 Stars
689 Commits
105 Forks
12 Watchers
8 Branches
19 Contributors
Updated on Jul 08, 2025
Latest Version
4.1.0
Package Id
cross-fetch@4.1.0
Unpacked Size
91.07 kB
Size
21.59 kB
File Count
13
NPM Version
10.8.2
Node Version
20.18.1
Published on
Dec 21, 2024
Cumulative downloads
Total Downloads
Last Day
-2.3%
964,530
Compared to previous day
Last Week
-8.3%
18,521,016
Compared to previous week
Last Month
1.2%
80,756,391
Compared to previous month
Last Year
12.3%
859,184,238
Compared to previous year
1
31
Universal WHATWG Fetch API for Node, Browsers, Workers and React Native. The scenario that cross-fetch really shines is when the same JavaScript codebase needs to run on different platforms.
1npm install --save cross-fetch
As a ponyfill (imports locally):
1// Using ES6 modules with Babel or TypeScript 2import fetch from 'cross-fetch'; 3 4// Using CommonJS modules 5const fetch = require('cross-fetch');
As a polyfill (installs globally):
1// Using ES6 modules 2import 'cross-fetch/polyfill'; 3 4// Using CommonJS modules 5require('cross-fetch/polyfill');
The CDN build is also available on unpkg:
1<script src="//unpkg.com/cross-fetch/dist/cross-fetch.js"></script>
This adds the fetch function to the window object. Note that this is not UMD compatible.
With promises:
1import fetch from 'cross-fetch'; 2// Or just: import 'cross-fetch/polyfill'; 3 4fetch('//api.github.com/users/lquixada') 5 .then(res => { 6 if (res.status >= 400) { 7 throw new Error("Bad response from server"); 8 } 9 return res.json(); 10 }) 11 .then(user => { 12 console.log(user); 13 }) 14 .catch(err => { 15 console.error(err); 16 });
With async/await:
1import fetch from 'cross-fetch'; 2// Or just: import 'cross-fetch/polyfill'; 3 4(async () => { 5 try { 6 const res = await fetch('//api.github.com/users/lquixada'); 7 8 if (res.status >= 400) { 9 throw new Error("Bad response from server"); 10 } 11 12 const user = await res.json(); 13 14 console.log(user); 15 } catch (err) { 16 console.error(err); 17 } 18})();
You can find a comprehensive doc at Github's fetch page. If you want to play with cross-fetch, check our JSFiddle playground.
Tip: Run the fiddle on various browsers and with different settings (for instance: cross-domain requests, wrong urls or text requests). Don't forget to open the console in the test suite page and play around.
I did a lot of research in order to find a fetch library that could be simple, cross-platform and provide polyfill as an option. There's a plethora of libs out there but none could match those requirements.
In a word? Risk. If the spec changes in the future, it might be problematic to debug. Read more about it on sindresorhus's ponyfill page. It's up to you if you're fine with it or not.
Just like isomorphic-fetch, it is just a proxy. If you're in node, it delivers you the node-fetch library, if you're in a browser or React Native, it delivers you the github's whatwg-fetch. The same strategy applies whether you're using polyfill or ponyfill.
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
---|---|---|---|---|---|
The New York Times | Apollo GraphQL | Swagger | VulcanJS | graphql-request |
Heavily inspired by the works of matthew-andrews. Kudos to him!
cross-fetch is licensed under the MIT license © Leonardo Quixadá
@lquixada |
6.1/10
Summary
Incorrect Authorization in cross-fetch
Affected Versions
< 2.2.6
Patched Versions
2.2.6
6.1/10
Summary
Incorrect Authorization in cross-fetch
Affected Versions
>= 3.0.0, < 3.1.5
Patched Versions
3.1.5
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
binaries present in source code
Details
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
Found 0/29 approved changesets -- score normalized to 0
Reason
dangerous workflow patterns detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
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