Registry / devops / tiny-fetch-json

tiny-fetch-json

JSON →
library2.0.1jsnpmunverified

Minimal wrapper around the global Fetch API for simpler JSON API consumption. Current stable version is 2.0.1, a single small file with TypeScript types. Unlike axios or node-fetch, it has zero dependencies and uses the built-in fetch available in Node 18+. The library throws on non-2xx responses and returns parsed JSON directly.

npm install tiny-fetch-json
INSTALL
IMPORT
SIG · TINY-FETCH-JSON
T
tiny-fetch-json
devopsjavascriptv2.0.1
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 (fetchJson)
import fetchJson from 'tiny-fetch-json'
import { fetchJson } from 'tiny-fetch-json'
The package has a default export, not a named export.
default (fetchJson) CommonJS
const fetchJson = require('tiny-fetch-json')
const { fetchJson } = require('tiny-fetch-json')
CommonJS require returns the default export as the entire module.
type FetchJsonOptions
import type { FetchJsonOptions } from 'tiny-fetch-json'
TypeScript types are included; FetchJsonOptions is likely just RequestInit.

Shows ESM import and basic usage with a JSON API, including error handling.

import fetchJson from 'tiny-fetch-json'; const getTodos = async () => { try { const data = await fetchJson('https://jsonplaceholder.typicode.com/todos/1'); console.log(data); } catch (error) { console.error('Request failed:', error); } }; getTodos();
Debug
Known issues
breakingVersion 2.0.0 changed from CommonJS to ESM-only. Requires Node >=18 and 'type': 'module' in package.json or .mjs extension.
fix
Use dynamic import() from CommonJS or migrate to ESM. Alternatively stay on 1.x.
affects: >=2.0.0
gotchaThe library relies on global fetch (built-in Node 18+). In older Node versions or non-standard environments, fetch must be polyfilled or provided globally.
fix
Ensure global fetch is available. Use undici or node-fetch polyfill if needed.
affects: >=2.0.0
gotchaErrors are thrown for any non-2xx status; there is no option to disable this. The error message includes the status code but not the response body.
fix
Wrap calls in try-catch. To get the response body on error, you must use the native fetch directly.
affects: all
Errors
Common errors & fixes
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'tiny-fetch-json'
Using require() in a CommonJS file with version 2.0.0+ which is ESM-only.
fix
Use import('tiny-fetch-json') dynamic import or migrate to ESM.
TypeError: fetchJson is not a function
Incorrect import syntax, e.g. named import instead of default import.
fix
Use 'import fetchJson from 'tiny-fetch-json'' or 'const fetchJson = require('tiny-fetch-json')'.
ReferenceError: fetch is not defined
Environment lacks the Fetch API (e.g., Node.js <18 without polyfill).
fix
Provide a global fetch polyfill such as 'undici' or 'node-fetch'.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
tiny-fetch-json — npm install tiny-fetch-json · libregistry