PouchDB HTTP-only Adapter
PouchDB-http is a minimalist preset package designed to provide only the HTTP adapter for PouchDB. Its primary function is to allow applications to interact with a CouchDB-compatible server (like Apache CouchDB or Cloudant) without including any local storage adapters or map/reduce capabilities by default. This makes it suitable for scenarios where PouchDB is used purely as an interface to a remote database, reducing bundle size by omitting unnecessary features. The package is at version 6.0.2, which is significantly older than the current PouchDB core (8.x). As a result, its release cadence is effectively non-existent, and it lacks the continuous updates and features found in the main PouchDB project. Its key differentiator is its small footprint and specific focus on HTTP communication, but its age means it likely faces compatibility challenges with modern JavaScript environments and newer PouchDB plugins.
Common errors
-
TypeError: db.query is not a function
cause `pouchdb-http` does not include map/reduce (the `query` API) by default.fixAdd the map/reduce plugin: `const PouchDB = require('pouchdb-http').plugin(require('pouchdb-mapreduce'));` -
UnhandledPromiseRejectionWarning: TypeError: Cannot read properties of undefined (reading 'get')
cause Attempting to create a local PouchDB instance without a specified HTTP URL, and no local adapter is present.fixAlways initialize `pouchdb-http` with a full HTTP/HTTPS URL to a CouchDB-compatible server, e.g., `new PouchDB('http://127.0.0.1:5984/mydb')`. -
SyntaxError: Named export 'PouchDB' not found. The requested module 'pouchdb-http' does not provide an export named 'PouchDB'
cause Attempting to import `pouchdb-http` using ES module syntax (e.g., `import { PouchDB } from 'pouchdb-http';`) which is not supported by this CommonJS-only package version.fixUse CommonJS `require` syntax: `const PouchDB = require('pouchdb-http');`
Warnings
- breaking This package is at version 6.0.2, while the main PouchDB library is significantly more advanced (v8.x). It is considered abandoned and has not received updates since 2017. Using this package means foregoing bug fixes, performance improvements, and security patches present in newer PouchDB versions.
- gotcha pouchdb-http only provides the HTTP adapter. It does not include local storage adapters (like IndexedDB, WebSQL, or LevelDB) or the `query()` API (map/reduce) by default. Attempts to use `PouchDB('mydb')` without an HTTP URL or to call `db.query()` will fail unless specific plugins are added.
- breaking Due to its age, `pouchdb-http` (v6.0.2) is not officially compatible with modern Node.js versions (e.g., Node.js 16+ or ESM-only environments). It relies heavily on CommonJS `require` syntax and may not function correctly without specific transpilation or legacy runtime settings.
Install
-
npm install pouchdb-http -
yarn add pouchdb-http -
pnpm add pouchdb-http
Imports
- PouchDB
import PouchDB from 'pouchdb-http';
const PouchDB = require('pouchdb-http'); - PouchDB.plugin
import PouchDB from 'pouchdb-http'; PouchDB.plugin(MapReducePlugin);
const PouchDB = require('pouchdb-http').plugin(require('pouchdb-mapreduce'));
Quickstart
const PouchDB = require('pouchdb-http');
// Initialize PouchDB with a remote CouchDB URL
const db = new PouchDB('http://127.0.0.1:5984/mydb');
// Example: Put a document
db.put({
_id: 'mydoc',
title: 'Hello PouchDB HTTP',
date: new Date().toISOString()
}).then((response) => {
console.log('Document created:', response);
return db.get('mydoc');
}).then((doc) => {
console.log('Document retrieved:', doc);
}).catch((err) => {
console.error('Error:', err);
});