node-fetch VS Nock

Compare node-fetch vs Nock and see what are their differences.

node-fetch

A light-weight module that brings the Fetch API to Node.js (by node-fetch)

Nock

HTTP server mocking and expectations library for Node.js (by nock)
Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
node-fetch Nock
90 21
8,622 12,499
0.5% 0.4%
1.7 8.3
23 days ago 2 days ago
JavaScript JavaScript
MIT License MIT License
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

node-fetch

Posts with mentions or reviews of node-fetch. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2024-03-13.
  • OAuth 2.0 implementation in Node.js
    3 projects | dev.to | 13 Mar 2024
    Note: In case you run into install reference error: fetch isn’t defined, ensure you install node-fetch
  • 5 Ways to Make HTTP Requests in Node.js
    3 projects | dev.to | 20 Feb 2024
    Node Fetch is a JavaScript library tailored for Node.js that simplifies making HTTP requests. It offers a straightforward and Promise-based approach for fetching resources from the internet or server, such as GET, POST, PUT, and DELETE requests. Designed for server-side applications, it's compatible with the Fetch API, allowing easy code transition between client-side and server-side environments.
  • CommonJS Is Hurting JavaScript
    7 projects | news.ycombinator.com | 30 Jun 2023
    Would anyone be interested in an article about the crusade to move JS to ESM? I've been considering writing one, here's a preview:

    Sindresorus wrote a gist "Pure ESM modules"[0] and converted all his modules to Pure ESM, breaking anyone `require`ing his code; he later locked the thread to prevent people from complaining. node-fetch released a pure ESM version a year ago that is 16x less popular than the CommonJS version[1]. The results of these changes broke a lot of code and resulted in many hours of developers figuring out how make their projects compatible with Pure ESM modules (or decide to ignore them and use old CommonJS versions)--not to mention the tons of pointless drama on GitHub issues.

    Meanwhile, TC-39 member Matteo Collima advocated a moderate approach dependent on where your module will be run [2]. So the crusade is led not by the Church, but by a handful of zealots dedicated to establishing ESM supremacy for unclear reasons (note how Sindresorus' gist lacks any justifications). It's kind of like the Python 2 to 3 move except with even less rationale and not driven by the core devs.

    0 - https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3...

    1 - https://www.npmjs.com/package/node-fetch?activeTab=versions

    2 - https://github.com/nodejs/node/issues/33954#issuecomment-924...

  • Next-Level Technical Blogging with Dev.to API
    2 projects | dev.to | 13 Jun 2023
    The API is CORS-enabled, meaning you’ll have to use the getArticles() functions from your backend. For making the actual request, you can use the fetch() function, available since Node.js v18. For older versions of Node.js, you can use a fetch()-compatible library like node-fetch.
  • How to Parse RSS Feed in Javascript
    2 projects | dev.to | 20 Mar 2023
    The RSS feed's URL will then need to be requested over the network. The native fetch API of JavaScript will be used since it is the most efficient. It undoubtedly works in browsers, and it appears that Node has a pretty well-liked implementation of it.
  • Exploring the Most Commonly Used Folder Names in Popular NPM Packages
    12 projects | dev.to | 23 Feb 2023
    docs: Documentation is an essential part of any package, as it provides users with the information they need to understand how to use it and how it works. The documentation usually includes usage instructions, API documentation, and more. It can also be included directly in the repository's README.md file, but it's often split into multiple files and stored in this folder for ease of navigation and maintenance. Although the documentation files can be in any format, the most common one is Markdown. Example from node-fetch.
  • Turn CV to structured data with GPT-3 and Node.js
    4 projects | dev.to | 24 Jan 2023
    node-fetch - NodeFetch is used to fetch the CV document.
  • Stop polyfilling fetch in your npm package
    10 projects | dev.to | 10 Jan 2023
    So for all versions of Node.js ≤17, you’ll need a Node fetch polyfill, the most popular of which is node-fetch: https://github.com/node-fetch/node-fetch
  • Exploring competitive features in Node.js v18 and v19
    10 projects | dev.to | 6 Dec 2022
    Before Node.js v18, you had to install node-fetch or Axios to request a resource from a server. With Node.js v18, you no longer need to install either package thanks to v18’s experimental Fetch API, which is available globally.
  • Scaling Your Compute Resources on Salesforce
    5 projects | dev.to | 5 Dec 2022
    Best of all, since this particular function runs on Node.js, you can install and use any NPM package to supplement your code. Let’s do that right now by installing node-fetch to issue our HTTP request:

Nock

Posts with mentions or reviews of Nock. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-03-13.
  • I made wirepig, a simple way to mock HTTP and TCP dependencies in tests.
    3 projects | /r/node | 13 Mar 2023
    That said, folks seem to like "recording" features in these sorts of tools (Ruby's VCR, nock, etc), so maybe there's a future where I add something similar. I've always just found the ergonomics of those features awkward to deal with, especially having to flip back and forth between tests and fixtures files to figure out what's wired to what, but maybe there's a clean solution... perhaps a "live request" mode that just prints mock code snippets of request/response pairs passing through your app.
    3 projects | /r/node | 13 Mar 2023
    When it comes time to test these applications, things can get awkward. Do I stand up a real redis instance to test against? Do I stub out functions to "fake" the network calls? Do I use a tool like nock that monkey patches node's standard lib?
  • Is there a better way to mock an axios call?
    2 projects | /r/reactjs | 28 Jan 2023
    While not mocking per say I usually use nock for http calls. You can use nock.recorder.rec() to capture the http call to play back during test, That way you are always using "live" code but not making real calls to servers.
  • How do you practice with React without setting up your own backend?
    6 projects | /r/reactjs | 3 Dec 2022
  • OSD600 - Telescope - Testing for feed URLs
    4 projects | dev.to | 20 Nov 2022
    I looked at the service which is used to get the feed URLs from a blog URL and noticed it takes the html response of the blog URL and gets the links ( tags) by checking the type attribute value against a list of valid feed values. So, I decided to use a similar approach by getting the html response for a provided URL and checking the Content-Type header against a list of valid MIME types for a feed. I ended up updating the logic to test if a URL is a feed URL, returning it if true. If the URL is found to not be a feed URL, it would try to get the feed URLs assuming the URL is a blog URL. I tested and confirmed that the new logic worked for both blog and feed URLs. Then, I added some tests for the new function I added to test for a feed URL. Testing this ended up being simpler than I expected as all I had to do was mock the response of a test url (using nock), and then check if the function returned the correct boolean value for a url. I created a PR and noticed that some of the tests in another file were now failing. While I was investigating this, I got a review on my PR, requesting me to add another test to the file which had the failing tests. That file tested the API service as a whole. I found out that nock only mocks a URL's response for one request by default. And since I was now checking for a feed URL as well, the function which returned the feed URLs from a blog URL was throwing an error since the nock for that was used up. To fix this, I had to specify in the nock statement to mock the URL response for two requests:
  • What features would you consider missing/nice to haves for backend web development in Rust?
    6 projects | /r/rust | 4 Nov 2022
  • Axios shipped a buggy version and it broke many productions apps. Let this be a lesson to pin your dependencies!
    5 projects | /r/node | 7 Oct 2022
    For example in my backend project I use Nock to do so. This library captures the request before sending them and you can validate the expected url to have all properties required.
    5 projects | /r/node | 7 Oct 2022
    There are libraries like https://github.com/nock/nock to prevent mocking the whole axios.
  • Is it acceptable to use mock servers, like Postman, for testing in Android?
    3 projects | /r/androiddev | 6 Sep 2022
    If you’re willing to venture into nodejs territory, then nock is a fantastic and simple to set up http mock server. https://github.com/nock/nock
  • Mocking API calls in React Tests with Nock
    5 projects | dev.to | 16 Aug 2022
    We'll use a third-party package called nock that helps us to mock HTTP requests. With nock, we can specify the desired behavior of our mock HTTP requests, including the URL, headers, and body. This allows us to test our code against a known data set, making debugging and testing much more straightforward.

What are some alternatives?

When comparing node-fetch and Nock you can also consider the following projects:

axios - Promise based HTTP client for the browser and node.js

request - 🏊🏾 Simplified HTTP request client.

got - 🌐 Human-friendly and powerful HTTP request library for Node.js

cross-fetch - Universal WHATWG Fetch API for Node, Browsers and React Native.

msw - Seamless REST/GraphQL API mocking library for browser and Node.js.

undici - An HTTP/1.1 client, written from scratch for Node.js

superagent - Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.

isomorphic-fetch - Isomorphic WHATWG Fetch API, for Node & Browserify

http-proxy - A full-featured http proxy for node.js

Express - Fast, unopinionated, minimalist web framework for node.