Registry / devops / gofor
library3.0.6jsnpmunverified

Gofor is a lean, isomorphic fetch decorator that deep reverse merges default options, allowing per-request overrides. Current stable version is 3.0.6. It supports Node.js >=8.9.0 and browsers, using the native fetch API or a polyfill. Compared to similar libraries like ky or wretch, Gofor focuses on simplicity and minimal configuration, providing a single class with a config method for setting defaults (including headers as objects or Headers instances) and a pre-configured fetch instance. It has no runtime dependencies and ships as CommonJS only.

npm install gofor
INSTALL
IMPORT
SIG · GOFOR
G
gofor
devopsjavascriptv3.0.6
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.

Gofor
import Gofor from 'gofor'
const Gofor = require('gofor').default
ESM default import works. CommonJS users use require('gofor') directly.
gofor
import { gofor } from 'gofor'
const gofor = require('gofor').gofor
Named export for a pre-configured instance. ESM destructuring import is correct; CommonJS works similarly but require is also acceptable.
GoforConfig
import type { GoforConfig } from 'gofor'
import { GoforConfig } from 'gofor'
Type-only import for TypeScript users. GoforConfig is not a runtime export.

Instantiate a Gofor with default auth header, perform a fetch, and show pre-configured instance usage with config method.

import Gofor from 'gofor'; const myGofor = new Gofor({ headers: { 'Authorization': `Bearer ${process.env.API_KEY ?? ''}` } }); myGofor.fetch('https://api.example.com/data') .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error)); // Or using the pre-configured instance: import { gofor } from 'gofor'; gofor.config({ credentials: 'include' }); gofor('https://api.example.com/public') .then(res => res.text()) .then(console.log);
Debug
Known issues
breakingIn v3, the server entry point 'gofor/server' has been removed; use the main isomorphic import instead.
fix
Replace require('gofor/server') with require('gofor') or the ESM equivalent.
affects: >=3.0.0
breakingIn v3, the 'dist' folder has been deprecated and no longer shipped; files are now in the root package.
fix
Update any imports referencing 'gofor/dist/...' to use the main entry point directly.
affects: >=3.0.0
gotchaGofor does not ship with a fetch polyfill; in Node.js <18 you must provide one (e.g., node-fetch) or install a global fetch.
fix
Install node-fetch (v2 for CommonJS, v3 for ESM) and set globalThis.fetch = require('node-fetch') or use an import.
affects: *
gotchaThe 'gofor' named export creates a new instance on each require/import; it is not a singleton.
fix
Assign the import to a constant if you need a single shared instance across modules.
affects: *
deprecatedThe default export Gofor is a class; using new Gofor() with options is the recommended way to create instances.
fix
Prefer instantiation with new Gofor({...}) over the legacy gofor.config() pattern if you need multiple configs.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: gofor is not a function
Using the named export incorrectly as a function without calling gofor.config() or importing the class.
fix
Use import { gofor } from 'gofor' and then call gofor(url) or gofor.fetch(url).
Module not found: Can't resolve 'gofor/server'
Importing the removed server entry point in v3.
fix
Change import to 'gofor' directly.
Cannot find module 'gofor/dist/gofor'
Attempting to import from the deprecated dist folder in v3.
fix
Use import from 'gofor' instead.
fetch is not defined
Running in a Node.js environment without a fetch polyfill.
fix
Install and set up a fetch polyfill like 'node-fetch' before using Gofor.
Property 'config' does not exist on type 'typeof import("gofor")'
TypeScript cannot find the config method if importing the class default instead of the named export.
fix
Use import { gofor } from 'gofor' for the pre-configured instance, or import Gofor and create a new instance.
Upgrade
Version history
3.0.6latest on npm
Audit
Dependencies
node-fetchoptionalTypically required as a fetch polyfill in Node.js environments where native fetch is unavailable; not a hard dependency but commonly used together.
Agent activity
6 hits · last 30 days
node
6
Resources
packagegofor
gofor — npm install gofor · libregistry