Registry / devops / advanced-fetch

advanced-fetch

JSON →
library3.1.2jsnpmunverified

A wrapper around node-fetch that adds automatic cookie handling, easy query/form/JSON body serialization, and optional cookie persistence to disk. Version 3.1.2 is the current stable release. Maintained via GitHub Actions. Simplifies common fetch patterns compared to raw node-fetch by providing convenience methods for GET, POST, PUT, DELETE with built-in encoding support via iconv-lite. Ships TypeScript type definitions.

npm install advanced-fetch
INSTALL
IMPORT
SIG · ADVANCED-FETCH
A
advanced-fetch
devopsjavascriptv3.1.2
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.

Fetch
import { Fetch } from 'advanced-fetch'
import Fetch from 'advanced-fetch'
Fetch is a named export, not default. Requires node-fetch (peer dependency).
Constructor options
const fetch = new Fetch({ cookiesFilename: 'cookies.json', encoding: 'win1251' })
new fetch()
Constructor parameter is an object; using function call without new throws.
Request methods
const result = await fetch.get('http://example.com', { query: { key: 'value' }, returnBuffer: true })
fetch.get('http://example.com', 'query=value')
Second parameter is an options object, not a query string directly. Use `query` property.

Creates a Fetch instance with cookie persistence, sends a POST request with JSON body and query params.

import { Fetch } from 'advanced-fetch'; import { load } from 'tough-cookie'; // For types: import type { Fetch as FetchType } from 'advanced-fetch'; async function main() { const fetch = new Fetch({ cookiesFilename: 'cookies.json' }); const result = await fetch.post('https://example.com/api', { json: { username: 'admin', password: process.env.PASSWORD ?? '' }, query: { version: 2 }, }); console.log(result); } main().catch(console.error);
Debug
Known issues
breakingv3 changed constructor signature from Fetch(url, options) to new Fetch(options). Old usage breaks.
fix
Use new Fetch({ cookiesFilename: '', encoding: '' }).
affects: >=3.0.0
deprecatedtough-cookie v4 has breaking changes for serialization format. Not fully compatible.
fix
Pin tough-cookie to v3 or implement custom cookie jar.
affects: >=3.0.0
gotchaRequest methods (get, post, etc.) return the response body as a string unless returnBuffer: true is set. Binary data not handled automatically.
fix
Set returnBuffer: true to get a Buffer for binary responses.
affects: *
gotchaencoding option uses iconv-lite. Invalid encoding names cause runtime errors.
fix
Use valid iconv-lite encoding names; see iconv-lite documentation.
affects: *
deprecatedquerystring module used for query serialization; deprecated in Node.js. Use custom serializer if needed.
fix
Pass query as a string or use a different library for complex queries.
affects: *
Errors
Common errors & fixes
TypeError: advanced_fetch_1.Fetch is not a constructor
Using default import instead of named import.
fix
import { Fetch } from 'advanced-fetch'
Cannot find module 'node-fetch'
Missing peer dependency node-fetch.
fix
npm install node-fetch
Cookies not persisting across requests
No cookiesFilename provided or file not writable.
fix
Pass { cookiesFilename: '/path/to/cookies.json' } to constructor.
Upgrade
Version history
3.1.2latest on npm
Audit
Dependencies
node-fetchrequiredcore HTTP client used under the hood
Agent activity
45 hits · last 30 days
node
40
OpenAI (training)
1
Resources
advanced-fetch — npm install advanced-fetch · libregistry