Registry / database / couchdb-compile

couchdb-compile

JSON →
library1.11.2jsnpmunverified

couchdb-compile is a Node.js utility designed to build CouchDB documents from various sources, including local directory trees, JSON files, or CommonJS modules. It processes a hierarchical filesystem structure, mirroring the CouchDB design document mapping, and converts it into a single JSON document suitable for direct upload to CouchDB. The current stable version is 1.11.2, with the last significant update in late 2021. Its release cadence has been infrequent in recent years, primarily focusing on bug fixes and dependency updates within the 1.x series. A key differentiator is its adherence to the Couchapp Filesystem Mapping, providing a structured way to manage CouchDB design documents and attachments outside the database, simplifying deployment and version control compared to manual JSON construction.

npm install couchdb-compile
INSTALL
IMPORT
SIG · COUCHDB-COMPILE
C
couchdb-compile
databasejavascriptv1.11.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compile
const compile = require('couchdb-compile');
import { compile } from 'couchdb-compile';
This package is CommonJS-only. ES module imports are not supported.

Demonstrates compiling a CouchDB design document from a directory structure and an object, including attachments and function stringification.

const compile = require('couchdb-compile'); const fs = require('fs'); const path = require('path'); // Setup a dummy CouchDB directory structure for demonstration const projectPath = path.join(__dirname, 'my-couch-app-example'); fs.mkdirSync(path.join(projectPath, 'views', 'numbers'), { recursive: true }); fs.writeFileSync(path.join(projectPath, '_id'), '_design/my_app'); fs.writeFileSync(path.join(projectPath, 'language'), 'javascript'); fs.writeFileSync(path.join(projectPath, 'views', 'numbers', 'map.js'), ` function (doc) { if (doc.type === 'number') { emit(doc.value, null); } } `); fs.writeFileSync(path.join(projectPath, 'views', 'numbers', 'reduce.js'), ` function (keys, values, rereduce) { return sum(values); } `); fs.mkdirSync(path.join(projectPath, '_attachments'), { recursive: true }); fs.writeFileSync(path.join(projectPath, '_attachments', 'logo.txt'), 'Hello from logo!'); console.log('Compiling CouchDB document from directory:', projectPath); compile(projectPath, function(error, doc, attachments) { if (error) { console.error('Error compiling:', error); return; } console.log('Compiled CouchDB document:'); console.log(JSON.stringify(doc, null, 2)); if (attachments) { console.log('\nCompiled attachments:'); console.log(JSON.stringify(attachments.map(att => ({ name: att.name, content_type: att.content_type, data_length: att.data.length // Don't log full buffer content })), null, 2)); } // Cleanup the dummy directory fs.rmSync(projectPath, { recursive: true, force: true }); console.log('Cleaned up dummy directory.'); }); // Example with an object source and function stringification compile({ foo: function () { return 42 }, bar: 'baz' }, (error, result) => { if (error) { console.error('Error compiling object:', error); return; } console.log('\nCompiled from object with function stringification:'); console.log(JSON.stringify(result, null, 2)); });
Debug
Known issues
gotchaFunctions defined within JavaScript objects or modules provided as source are stringified (using .toString()) and included as strings in the final CouchDB document, not executed. This is standard behavior for CouchDB design documents.
fix
Be aware that client-side logic embedded in CouchDB design documents must be self-contained JavaScript strings. Test the stringified output for correctness.
affects: >=1.0.0
gotchaFile extensions are stripped when forming property names in the CouchDB document from a directory source. For example, 'validate_doc_update.js' becomes the 'validate_doc_update' property.
fix
Ensure your file names accurately reflect the desired property names in the resulting JSON, excluding their extensions.
affects: >=1.0.0
gotchaAttachments are handled specially when placed in a '_attachments' directory, converting them into base64 encoded data with computed content types. The 'multipart' option can alter how attachments are returned via the callback.
fix
Consult the documentation for the '_attachments' directory structure and the 'multipart' option to ensure correct attachment processing for your use case.
affects: >=1.0.0
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, stat 'YOUR_PATH'
The specified `source` path (directory or file) does not exist or is inaccessible.
fix
Verify the `source` argument points to an existing directory or file. Use an absolute path or ensure it's relative to `process.cwd()`.
TypeError: compile is not a function
Attempting to use `compile` with ES module syntax (e.g., `import { compile } from '...'`) when the package is CommonJS-only, or incorrect destructuring.
fix
Use CommonJS `require` syntax: `const compile = require('couchdb-compile');` as the library does not support ES module imports.
SyntaxError: Unexpected token { in JSON at position X
The JSON file provided as a `source` argument is malformed or contains invalid syntax.
fix
Inspect the JSON source file for syntax errors, ensuring it is valid JSON.
Upgrade
Version history
1.11.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
couchdb-compile — npm install couchdb-compile · libregistry