{"id":16322148,"url":"https://github.com/1999/node-couchdb","last_synced_at":"2025-04-07T15:06:42.798Z","repository":{"id":6267272,"uuid":"7500611","full_name":"1999/node-couchdb","owner":"1999","description":"ES2015-compatible package to interact with CouchDB","archived":false,"fork":false,"pushed_at":"2023-09-16T09:12:27.000Z","size":337,"stargazers_count":76,"open_issues_count":14,"forks_count":29,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-31T13:17:36.555Z","etag":null,"topics":["couchdb","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/1999.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-01-08T11:43:59.000Z","updated_at":"2024-09-08T02:27:55.000Z","dependencies_parsed_at":"2024-12-24T04:29:16.751Z","dependency_job_id":null,"html_url":"https://github.com/1999/node-couchdb","commit_stats":{"total_commits":135,"total_committers":17,"mean_commits":"7.9411764705882355","dds":0.5037037037037038,"last_synced_commit":"4825580ec2d8cd8b1c490266f4ced3395c2cc8ee"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1999%2Fnode-couchdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1999%2Fnode-couchdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1999%2Fnode-couchdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1999%2Fnode-couchdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1999","download_url":"https://codeload.github.com/1999/node-couchdb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675597,"owners_count":20977376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["couchdb","nodejs"],"created_at":"2024-10-10T22:50:09.684Z","updated_at":"2025-04-07T15:06:42.773Z","avatar_url":"https://github.com/1999.png","language":"JavaScript","readme":"# node-couchdb [![Build Status](https://secure.travis-ci.org/1999/node-couchdb.svg?branch=master)](http://travis-ci.org/1999/node-couchdb) [![Dependency Status](https://david-dm.org/1999/node-couchdb.svg)](https://david-dm.org/1999/node-couchdb) [![devDependency Status](https://david-dm.org/1999/node-couchdb/dev-status.svg)](https://david-dm.org/1999/node-couchdb#info=devDependencies) [![Greenkeeper badge](https://badges.greenkeeper.io/1999/node-couchdb.svg)](https://greenkeeper.io/)\n\n`node-couchdb` package provides an easy way to interact with CouchDB using preferred cache layer:\n\n * [process memory](https://www.npmjs.com/package/node-couchdb-plugin-memory)\n * [memcached](https://www.npmjs.com/package/node-couchdb-plugin-memcached)\n * place for your plugin :)\n\n# Installation\n``` bash\nnpm install node-couchdb --save\n```\n\n# API\n## Constructor\n`node-couchdb` exports constructor, which accepts one object argument with properties `host` (127.0.0.1 by default), `port` (5984 by default), `protocol` (http by default), `cache` (one of plugins, null by default), `auth` (object with properties `{user, pass}`) and `timeout` for all requests (5000 by default). All object fields are optional.\n\nES Module:\n```javascript\nimport NodeCouchDb from 'node-couchdb';\n```\n\nCommon JS:\n```javascript\nconst NodeCouchDb = require('node-couchdb');\n```\n\n```javascript\n// node-couchdb instance with default options\nconst couch = new NodeCouchDb({\n    auth: {\n        user: AUTH_USER,\n        pass: AUTH_PASS\n    }\n});\n\n// node-couchdb instance with Memcached\nconst MemcacheNode = require('node-couchdb-plugin-memcached');\nconst couchWithMemcache = new NodeCouchDb({\n    cache: new MemcacheNode,\n    auth: {\n        user: AUTH_USER,\n        pass: AUTH_PASS\n    }\n});\n\n// node-couchdb instance talking to external service\nconst couchExternal = new NodeCouchDb({\n    host: 'couchdb.external.service',\n    protocol: 'https',\n    port: 6984,\n    auth: {\n        user: AUTH_USER,\n        pass: AUTH_PASS\n    }\n});\n\n```\n\nAll node-couchdb methods return Promise instances which resolve if everything works as expected and reject with Error instance which usually has `code` and `body` fields. See package source and tests for more info.\n\n## Create database\n```javascript\ncouch.createDatabase(dbName).then(() =\u003e {...}, err =\u003e {\n    // request error occured\n});\n```\n\n## Drop database\n```javascript\ncouch.dropDatabase(dbName).then(() =\u003e {...}, err =\u003e {\n    // request error occured\n});\n```\n\n## List databases\n```javascript\ncouch.listDatabases().then(dbs =\u003e dbs.map(...), err =\u003e {\n    // request error occured\n});\n```\n\n## Get document by its id\n```javascript\ncouch.get(\"databaseName\", \"some_document_id\").then(({data, headers, status}) =\u003e {\n    // data is json response\n    // headers is an object with all response headers\n    // status is statusCode number\n}, err =\u003e {\n    // either request error occured\n    // ...or err.code=EDOCMISSING if document is missing\n    // ...or err.code=EUNKNOWN if statusCode is unexpected\n});\n```\n\n## Get view results\n```javascript\nconst dbName = \"database\";\nconst startKey = [\"Ann\"];\nconst endKey = [\"George\"];\nconst viewUrl = \"_design/list/_view/by_firstname\";\n\nconst queryOptions = {\n    startkey: startKey,\n    endkey: endKey\n};\n\ncouch.get(dbName, viewUrl, queryOptions).then(({data, headers, status}) =\u003e {\n    // data is json response\n    // headers is an object with all response headers\n    // status is statusCode number\n}, err =\u003e {\n    // either request error occured\n    // ...or err.code=EDOCMISSING if document is missing\n    // ...or err.code=EUNKNOWN if statusCode is unexpected\n});\n```\n\n## Query using Mango\n```javascript\nconst dbName = \"database\";\nconst mangoQuery = {\n    selector: {\n        firstname: {\n            $gte: 'Ann',\n            $lt: 'George'\n        }\n    }\n};\n\ncouch.mango(dbName, mangoQuery).then(({data, headers, status}) =\u003e {\n    // data is json response\n    // headers is an object with all response headers\n    // status is statusCode number\n}, err =\u003e {\n    // either request error occured\n    // ...or err.code=EDOCMISSING if document is missing\n    // ...or err.code=EUNKNOWN if statusCode is unexpected\n});\n```\n\n## Insert a document\n```javascript\ncouch.insert(\"databaseName\", {\n    _id: \"document_id\",\n    field: [\"sample\", \"data\", true]\n}).then(({data, headers, status}) =\u003e {\n    // data is json response\n    // headers is an object with all response headers\n    // status is statusCode number\n}, err =\u003e {\n    // either request error occured\n    // ...or err.code=EDOCCONFLICT if document with the same id already exists\n});\n```\n\n## Update a document\n```javascript\n// note that \"doc\" must have both \"_id\" and \"_rev\" fields\ncouch.update(\"databaseName\", {\n    _id: \"document_id\",\n    _rev: \"1-xxx\"\n    field: \"new sample data\",\n    field2: 1\n}).then(({data, headers, status}) =\u003e {\n    // data is json response\n    // headers is an object with all response headers\n    // status is statusCode number\n}, err =\u003e {\n    // either request error occured\n    // ...or err.code=EFIELDMISSING if either _id or _rev fields are missing\n});\n```\n\n## Insert an attachment\n```javascript\ncouch.insertAttachment(\"databaseName\", \"document id\", \"attachment name\", \"attachment body\", \"doc revision\").then(({data, headers, status}) =\u003e {\n    // data is json response\n    // headers is an object with all response headers\n    // status is statusCode number\n}, err =\u003e {\n    // either request error occured\n    // ...or err.code=EFIELDMISSING if either _id or _rev fields are missing\n});\n```\n\n## Delete an attachment\n```javascript\n// note that \"doc\" must have both \"_id\" and \"_rev\" fields\ncouch.update(\"databaseName\", \"document id\", \"attachment name\", \"doc revision\").then(({data, headers, status}) =\u003e {\n    // data is json response\n    // headers is an object with all response headers\n    // status is statusCode number\n}, err =\u003e {\n    // either request error occured\n    // ...or err.code=EFIELDMISSING if either _id or _rev fields are missing\n});\n```\n\n## Use an update function\n```javascript\ncouch.updateFunction(\"databaseName\", \"designDocument\", \"updateFunction\", {optional query string}, \"docid\").then(({data, headers, status}) =\u003e {\n    // data is json response\n    // headers is an object with all response headers\n    // status is statusCode number\n}, err =\u003e {\n    // either request error occured\n    // ...or err.code=EFIELDMISSING if either _id or _rev fields are missing\n});\n```\n\n## Delete a document\n```javascript\ncouch.del(\"databaseName\", \"some_document_id\", \"document_revision\").then(({data, headers, status}) =\u003e {\n    // data is json response\n    // headers is an object with all response headers\n    // status is statusCode number\n}, err =\u003e {\n    // either request error occured\n    // ...or err.code=EDOCMISSING if document does not exist\n    // ...or err.code=EUNKNOWN if response status code is unexpected\n});\n```\n\n## Generate unique identifier(s)\n```javascript\n// get one unique id\ncouch.uniqid().then(ids =\u003e ids[0]);\n\n// get N unique ids\ncouch.uniqid(N).then(ids =\u003e ids.map(...));\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1999%2Fnode-couchdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1999%2Fnode-couchdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1999%2Fnode-couchdb/lists"}