Registry / devops / mande
library2.0.9jsnpmunverified

mande is a lightweight (~800 bytes) wrapper around the Fetch API that provides smart defaults for HTTP requests, including automatic JSON serialization/deserialization, error throwing on non-2xx responses, and automatic Content-Type headers. Version 2.0.9 is the latest stable release, with a relatively stable API and TypeScript support built-in. It differentiates from axios and ky by its minimal size, zero dependencies, and focus on simplicity. The library offers a clean, promise-based interface with GET, POST, PUT, PATCH, DELETE methods, global defaults, per-instance options, and request-level overrides. It works in modern browsers and Node.js with a fetch polyfill.

npm install mande
INSTALL
IMPORT
SIG · MANDE
M
mande
devopsjavascriptv2.0.9
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.

mande
import { mande } from 'mande'
import mande from 'mande'
mande is a named export, not a default export. CommonJS: const { mande } = require('mande')
defaults
import { defaults } from 'mande'
defaults is a named export for setting global options like headers.
MandeInstance
import type { MandeInstance } from 'mande'
TypeScript type for the mande instance.

Shows basic usage of mande: creating an instance, performing GET/POST/PUT/DELETE requests, and using TypeScript generics for typed responses.

import { mande } from 'mande'; // Create a mande instance for /api/todos const todos = mande('/api/todos', { headers: { Authorization: 'Bearer ' + (process.env.API_KEY ?? '') }, }); // GET /api/todos todos.get().then(data => console.log(data)).catch(err => console.error(err)); // POST /api/todos with JSON body todos.post({ text: 'Buy milk', done: false }).then(data => console.log(data)); // PUT /api/todos/1 todos.put(1, { text: 'Buy milk', done: true }); // DELETE /api/todos/1 todos.delete(1); // Custom request with type generic todos.get<{ id: number; text: string; done: boolean }[]>('/search?q=milk').then(todos => { console.log(todos[0].text); // typed });
Debug
Known issues
gotchaAll responses with status outside 200-299 throw an error. 4xx and 5xx are not silently returned.
fix
Use try/catch or .catch() to handle errors. The error object is an instance of the exported 'FetchError' type.
affects: >=0.0.0
gotchaThe 'mande()' function expects a base URL. Do not include a trailing slash; it is added automatically if missing.
fix
Use mande('/api') instead of mande('/api/') for consistency.
affects: >=2.0.0
deprecatedThe 'options' property on a mande instance is mutated directly; modifying it affects subsequent requests.
fix
Use the 'defaults' export or pass options per request instead of mutating instance.options.
affects: >=2.0.0
gotchaWhen passing 'null' as header value, the header is removed. This is intentional but can be surprising if 'null' is set accidentally.
fix
Explicitly delete the header or set it to undefined if you want to keep the key without value.
affects: >=2.0.0
gotchamande does not handle redirects automatically; it follows fetch's default behavior (follow redirects).
fix
To change redirect behavior, pass redirect option in the request options: { redirect: 'manual' }.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'mand' of ...
Mis-typo in import: 'mand' instead of 'mande'.
fix
Correct import: import { mande } from 'mande'
Uncaught (in promise) FetchError: ... (status: 404)
A request returned a 4xx or 5xx status and mande threw an error.
fix
Catch the error and check the response status: .catch(err => console.error(err.status))
SyntaxError: Unexpected token < in JSON at position 0
Response is not JSON, but mande automatically tries to parse JSON.
fix
Pass { responseAs: 'text' } or { responseAs: 'blob' } in request options to get non-JSON responses.
TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
Using mande in an environment without fetch (e.g., older Node.js without polyfill).
fix
Provide a fetch polyfill like 'node-fetch' and pass it as the third argument to mande().
Upgrade
Version history
2.0.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
packagemande
mande — npm install mande · libregistry