
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
nano
(short for nanocouch
) is a minimalistic couchdb
driver for node.js
npm install nano
a quick example using nano
to use nano
you have to either provide a) a json
configuration object
or b) a configuration file path
like cfg/tests.js
. refer to cfg/couch.example.js for a example
var nano = require('nano')('http://localhost:5984');
within the nano
variable you have various methods you can call. these include tasks like create, delete or list databases:
nano.db.create("alice");
in this function there is not callback. in nano
the absence of callback means "do this, ignore what happens"
you normally don't want to do that though:
// clean up the database we created previously
nano.db.destroy("alice", function(err,response,headers) {
nano.db.create("alice", function(){
// specify the database we are going to use
var alice = nano.use("alice");
alice.insert({crazy: true}, "rabbit", function(e,r,h){
if(e) { throw e; }
console.log("you have inserted the rabbit.")
});
});
});
the nano.use
method creates a scope
where you operate inside a single database. this is just a convenience so you don't have to specify the database name every single time you do an update or delete
// 5: var alice = nano.use("alice");
in nano
a callback has always three arguments
// 6: alice.insert({crazy: true}, "rabbit", function(e,r,h){
// 7: if(e) { throw e; }
// 8: console.log("you have inserted the rabbit.")
// 9: });
meaning:
e: the `error`, if any. check error.js for more info.
r: the http `response body` from couchdb, if no error.
h: the http response `headers` from couchdb, if no error.
that's it. don't forget to delete the database you created:
nano.db.destroy("alice");
for a small tutorial check out writings.nunojob.com/2011/08/nano-minimalistic-couchdb-client-for-nodejs.html
*
marks optional
params
are additional querystring parameters
nano.db.create(db_name,callback*)
nano.db.get(db_name,callback*)
nano.db.destroy(db_name,callback*)
nano.db.list(callback*)
nano.db.compact(db_name,design_name*,callback*)
nano.db.replicate(source,target,continuous*,callback*)
nano.db.changes(db_name,params*,callback*)
nano.use(db_name)
nano.request(opts,callback*)
nano.config
nano.use: [nano.db.use, nano.db.scope, nano.scope]
nano.request: [nano.relax, nano.dinosaur]
doc.insert(doc,doc_name*,callback*)
doc.destroy(doc_name,rev,callback*)
doc.get(doc_name,params*,callback*)
doc.bulk(docs,callback*)
doc.list(params*,callback*)
doc.attachment.insert(doc_name,att_name,att,content_type,params*,callback*)
doc.attachment.get(doc_name,att_name,params*,callback*)
doc.attachment.destroy(doc_name,att_name,rev,callback*)
nano.use
sets db_name
in scope so you don't have to specify it every time
nano.db.get: [doc.info(callback*)]
nano.db.replicate: [doc.replicate(target,continuous*,callback*)]
nano.db.compact: [doc.compact(callback*), doc.view.compact(design_name,callback*)]
nano.db.changes: [doc.changes(params*,callback*)]
nano
is minimalistic so it provides advanced users with a way to code their own extension functions:
nano.request(opts,callback*)
to get a document in a specific rev an advanced user might do:
nano.request( { db: "alice"
, doc: "rabbit"
, method: "GET"
, params: { rev: "1-967a00dff5e02add41819138abb3284d"}
},
function (_,b) { console.log(b) }
);
this is the same as (assuming alice = require('nano')('http://localhost:5984/alice')
):
alice.get("rabbit", {rev: "1-967a00dff5e02add41819138abb3284d"},
function (_,b) { console.log(b) }
);
you can pipe in nano
just like you do in any other stream. this is available in all methods:
alice.attachment.get("breakfast", "sugar", {rev: rev})
.pipe(fs.createWriteStream("/tmp/sugar-for-rabbit"));
check issues
everyone is welcome to contribute. patches, bugfixes, new features
nano
in githubgit checkout -b my_branch
git push origin my_branch
package.json
test/
and ./run
.always make sure all the tests pass before sending in your pull request!
we will tell santa
_
/ _) ROAR! i'm a vegan!
.-^^^-/ /
__/ /
/__.|_|-|_| cannes est superb
git clone git://github.com/dscape/nano.git
(oO)--',-
in caos
FAQs
The official CouchDB client for Node.js
The npm package nano receives a total of 27,379 weekly downloads. As such, nano popularity was classified as popular.
We found that nano demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.