explaingit

matthew-andrews/isomorphic-fetch

6,919JavaScriptAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

JavaScript library that adds the browser's built-in fetch() function to Node.js so the same HTTP request code runs unchanged on both the server and in the browser.

Mindmap

mindmap
  root((isomorphic-fetch))
    What it does
      Adds fetch to Node.js
      Same code everywhere
    How it works
      Global polyfill
      WHATWG Fetch based
    Install
      npm package
      Bower support
    Alternatives
      fetch-ponyfill
      node-fetch
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Write one fetch() function for HTTP requests that works in both the browser and your Node.js server without any changes

USE CASE 2

Add fetch support to an older Node.js project without modifying any existing fetch() call syntax

USE CASE 3

Share a data-fetching module between a React frontend and a Node.js backend for server-side rendering

Tech stack

JavaScriptNode.js

Getting it running

Difficulty · easy Time to first run · 5min

Modifies the global scope by attaching fetch as a global, use fetch-ponyfill instead if you prefer not to touch globals.

Use freely for any purpose including commercial projects as long as you keep the copyright notice.

In plain English

Isomorphic-fetch is a JavaScript library that makes the Fetch API available in Node.js environments. The Fetch API is a browser built-in for making HTTP requests: you use it to pull data from a server, submit data, or interact with external web services using a consistent, promise-based approach. Browsers support it natively, but Node.js, which runs JavaScript on the server side, does not include it by default. This library bridges that gap by adding a global fetch function to Node.js. Once installed, code that uses fetch to make network requests can run without modification in both the browser and on a Node.js server. That shared compatibility is what "isomorphic" refers to: the same code works in both environments. The README flags a few important points. Because this library attaches fetch as a global variable, it modifies the global scope of the Node.js environment. That is an intentional design decision kept for backward compatibility. Developers who prefer not to touch the global scope are pointed toward an alternative called fetch-ponyfill, which provides the same capability without modifying globals. Installation is through npm or Bower, the two common JavaScript package managers referenced in the README. Usage mirrors the standard browser Fetch API: require the library once at the top of your code to register the global, then call fetch with a URL and handle the returned promise. The library is built on top of GitHub's WHATWG Fetch polyfill and is released under the MIT license. The README also lists alternative libraries for developers who want more control over how fetch is provided in their project.

Copy-paste prompts

Prompt 1
I'm using isomorphic-fetch in a Node.js project. Show me how to require it and make a GET request to a JSON API, then parse the response body.
Prompt 2
My React app uses fetch() in the browser. I want the same code to run in Node.js for server-side rendering. How do I add isomorphic-fetch to make this work?
Prompt 3
Show me how to make a POST request with a JSON body using isomorphic-fetch in Node.js, including setting the Content-Type header.
Prompt 4
What is the difference between isomorphic-fetch and node-fetch, and when should I pick one over the other?
Open on GitHub → Explain another repo

← matthew-andrews on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.