Registry / storage / js-ipfs-fetch

js-ipfs-fetch

JSON →
library5.3.0jsnpmunverified

A library that provides a browser-compatible fetch() API for IPFS, allowing developers to fetch content from IPFS and IPNS URLs using the same interface as HTTP fetch. Version 5.3.0 is the latest stable release, with occasional updates. It wraps an IPFS instance (e.g., ipfs-core) and returns a fetch function that supports GET, PUT, HEAD methods, range requests, directory listings, and file uploads via FormData. Key differentiators: mimics Web Fetch API exactly, supports both ipfs:// and ipns:// schemes, and allows directory listing with HTML/JSON responses.

npm install js-ipfs-fetch
INSTALL
IMPORT
SIG · JS-IPFS-FETCH
J
js-ipfs-fetch
storagejavascriptv5.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import makeIpfsFetch from 'ipfs-fetch'
const { default: makeIpfsFetch } = require('ipfs-fetch')
ESM default export (function). For CJS use require('ipfs-fetch').default or destructure from default.
makeIpfsFetch
import makeIpfsFetch from 'ipfs-fetch'
import { makeIpfsFetch } from 'ipfs-fetch'
The module exports a single function as default, not a named export.
fetch
const fetch = await makeIpfsFetch({ ipfs })
const fetch = makeIpfsFetch({ ipfs })
makeIpfsFetch returns a Promise that resolves to the fetch function; must be awaited.

Creates an IPFS instance, initializes ipfs-fetch with it, fetches a file via IPFS URL, logs its text content, and stops the IPFS node.

import { create } from 'ipfs-core' import makeIpfsFetch from 'ipfs-fetch' const ipfs = await create() const fetch = await makeIpfsFetch({ ipfs }) const response = await fetch('ipfs://QmT5NvUtoP5fT6YcQK5c5gWj5H5j5H5j5H5j5H5j5H5j5') const text = await response.text() console.log(text) await ipfs.stop()
Debug
Known issues
gotchamakeIpfsFetch returns a Promise, not the fetch function directly.
fix
Always await makeIpfsFetch({ ipfs }) before using fetch.
affects: >=1.0.0
gotchaThe 'ipfs' parameter must be a properly initialized IPFS instance (e.g., from ipfs-core). Using a non-started instance will cause errors.
fix
Ensure ipfs is created and started before passing to makeIpfsFetch.
affects: >=1.0.0
gotchaDirectory URLs must end with a trailing slash to be treated as folder listings; otherwise they may be misinterpreted as files.
fix
Always append '/' to directory CIDs when fetching.
affects: >=1.0.0
deprecatedThe module previously used a callback-style API in older versions (<1.0). The current API is Promise-based.
fix
Upgrade to latest version and use async/await or .then() syntax.
affects: <1.0
Errors
Common errors & fixes
TypeError: makeIpfsFetch is not a function
Wrong import: using named import instead of default import.
fix
Use import makeIpfsFetch from 'ipfs-fetch' (default import).
Error: ipfs is not defined
Passing an undefined or uninitialized IPFS instance.
fix
const ipfs = await create(); const fetch = await makeIpfsFetch({ ipfs });
TypeError: fetch is not a function
Forgetting to await makeIpfsFetch; fetch is a property of the resolved promise?
fix
const fetch = await makeIpfsFetch({ ipfs });
TypeError: Failed to fetch (ipfs://...): No content
CID not found or IPFS node not connected to peers that have the content.
fix
Check that the CID exists and the IPFS node is connected to network.
Upgrade
Version history
5.3.0latest on npm
Audit
Dependencies
ipfs-corerequiredThe library requires a running IPFS instance to fetch content; ipfs-core is the reference implementation.
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
js-ipfs-fetch — npm install js-ipfs-fetch · libregistry