npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ncouch

v1.0.1

Published

A CouchDB driver for node.js.

Downloads

17

Readme

Introduction

ncouch is a couchdb server driver for node.js. It's uncomplete but works really well.

Usage

Code

var ncouch = require("ncouch");
var server = ncouch.server("http://127.0.0.1:5984/");
var database = server.database("test");
wrapper.view("artists/songs",function(err, resp) {
  if ( err ) {
    console.log("something failed badly: ", err, resp);
    return;
  }
  console.log("View response: ",resp);
});

wrapper.getDoc("docid1",function(err, doc) {
  if ( err ) {
    console.log("something failed badly: ", err, doc);
    return;
  }
  console.log("Doc: ", doc);
  doc.newProperty = "I'm new";
  wrapper.storeDoc(doc, function(err, resp) {
    if ( err ) {
      console.log("something failed badly: ", err, doc);
      return;
    }
    console.log("Doc recorded. New revision is : ", doc._rev);
  });
});

API

Server

var server = ncouch.server( url );

###Parameters

url: the URL of your CouchDB server

###Returns

A ncouch server object.

###Example

var server = ncouch.server("http://localhost:5984/");

Database

var db = server.database( name );

###Parameters

name: name of the CouchDB database

###Returns

a ncouch database object

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");

Database creation

server.createDatabase(name, callback)

###Parameters

name: name of the Couch database to create
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
server.createDatabase("test", function(err, resp) {
  if ( err ) {
    console.log("Database creation failed: ",err,resp);
  } else {
    console.log("database created");
  }
});

Database existence test

server.databaseExists(name, callback)

###Parameters

name: name of the database
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
server.databaseExists("test", function(err, resp) {
  if ( err ) {
    console.log("Database existence test failed");
  } else {
    if ( resp ) {
      console.log("database exists");
    } else {
      console.log("databse doesn't exist");
    }
  }
});

Document: get

db.getDoc(id, [data,] callback)

###Parameters

id: id of the document to fetch
data: optionnal data to be passed (an object of keys => values)
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
db.getDoc("docid1", {conflicts: true, open_revs: "all"}, function(err,doc) {
  if ( err ) {
    console.log("Document retrieval failed: ",err,doc);
    return ;
  }
  console.log("document retrieved: ",doc);
});

Document: store

db.storeDoc(doc, callback)

###Parameters

doc: the document to store
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
db.getDoc("docid1", {conflicts: true, open_revs: "all"}, function(err,doc) {
  if ( err ) {
    console.log("Document retrieval failed: ",err,doc);
    return ;
  }
  doc.newProperty = "property";
  db.storeDoc(doc, function(err, resp) {
    if ( err ) {
      console.log("document storage failed: ", err, resp);
      return ;
    }
    console.log("Doc stored, last revision is now", doc.rev);
  });
});

Document: delete

db.deleteDoc(doc, callback)

###Parameters

doc: the document to delete
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
db.getDoc("docid1", {conflicts: true, open_revs: "all"}, function(err,doc) {
  if ( err ) {
    console.log("Document retrieval failed: ",err,doc);
    return ;
  }
  doc.newProperty = "property";
  db.deleteDoc(doc, function(err, resp) {
    if ( err ) {
      console.log("document removal failed: ", err, resp);
      return ;
    }
    console.log("Doc deleted");
  });
});

Document: delete by id

db.deleteDoc(id, callback)

###Parameters

id: the id of the document to delete
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
db.deleteDoc("docid1", function(err, resp) {
  if ( err ) {
    console.log("document removal failed: ", err, resp);
    return ;
  }
  console.log("Doc deleted");
});

Document: storage of multiple docs in one go

db.storeDocs(docs, [data,] callback)

###Parameters

docs: array of documents to store
data: optionnal data to be passed (an object of keys => values)
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
var doc1 = {color: "red"};
var doc2 = {color: "blue"};
var docs = [doc1, doc2];
db.storeDocs(docs, function(err, resp) {
  if ( err ) {
    console.log("document storage failed: ", err, resp);
    return ;
  }
  console.log("Docs stored");
});

Document: overwriting a document

This will replace the document, without taking care of the document revision and conflict management of couchDB.

db.overwriteDoc(doc, cb)

###Parameters

doc: the document to store
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
db.getDoc("docid1", {conflicts: true, open_revs: "all"}, function(err,doc) {
  if ( err ) {
    console.log("Document retrieval failed: ",err,doc);
    return ;
  }
  var newDoc = {_id: "docid1", color: "black"};
  db.overwriteDoc(newDoc, function(err,resp) {
    if ( err ) {
      console.log("Document storage failed: ",err,resp);
      return ;
    }
    console.log("document stored, last revision is now",newDoc._rev);
  });
});

Documents: getting several documents in one go

db.getAlldocs([data,] callback)

###Parameters

data: optionnal data to be passed as options
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
db.getAllDocs(function(err, resp) {
  if ( err ) {
    console.log("Document retrieval failed: ",err,resp);
    return ;
  }
  console.log("I got all documents of the database",resp.rows);
});

###Example2: get several docs by id

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
db.getAllDocs([keys: ["docid1","docid2"]], function(err, resp) {
  if ( err ) {
    console.log("Document retrieval failed: ",err,resp);
    return ;
  }
  console.log("I got two documents of the database",resp.rows);
});

Documents: delete several documents in one go

db.deleteDocs(docs, [data,] callback)

###Parameters

docs: array of documents to delete
data: optionnal data to be passed (an object of keys => values)
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
db.getAllDocs([keys: ["docid1","docid2"]], function(err, resp) {
  if ( err ) {
    console.log("Document retrieval failed: ",err,resp);
    return ;
  }
  console.log("I got two documents of the database",resp.rows);
  db.deleteDocs(resp.rows, function(err, resp) {
    if ( err ) {
      console.log("failed to delete docs",err,resp);
      return;
    }
    console.log("documents deleted");
  });
});

View: query a view

db.view(name, [data,] callback)

###Parameters

name: name of the view, composed by the name of the design document, a /, and the name of the view
data: optionnal data to be passed (an object of keys => values)
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
db.view("artists/all", {reduce: false, include_docs: true}, function(err,resp) {
  if ( err ) {
    console.log("Error fetching the view: ",err,resp);
    return;
  }
  console.log("Got view results: ", resp.rows);
});

List: query a list

db.list(name, [data,] callback)

###Parameters

name: name of the list, composed by the name of the design document, a /, the name of the view, a /, optionnally, the name of the design document containing the list function and a /, the name of the list function
data: optionnal data to be passed (an object of keys => values)
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
db.list("artists/all/docs", {reduce: false, include_docs: true}, function(err,resp) {
  if ( err ) {
    console.log("Error fetching the list: ",err,resp);
    return;
  }
  console.log("Got list results: ", resp);
});

Show: query a show

db.show(name, [data,] callback)

###Parameters

name: name of the list, composed by the name of the design document, a /, the name of the show function, a /, and optionnally, the id of the document to show
data: optionnal data to be passed (an object of keys => values)
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
db.show("artist/public_profile/artist1", function(err,resp) {
  if ( err ) {
    console.log("Error fetching the show: ",err,resp);
    return;
  }
  console.log("Got show results: ", resp);
});

Update: calling an update function

See [http://wiki.apache.org/couchdb/Document_Update_Handlers](CouchDB Update API)

db.updateDoc(name, data, callback)

###Parameters

name: path of the update function, composed by the name of the design document, a /, the name of the update function, and optionnally, a / and the id of the document to update
data: additionnal data to pass to the update function
callback: a node style (err,resp) callback that will be called when the request is processed

###Example

var server = ncouch.server("http://localhost:5984/");
var db = server.database("test");
db.update("artist/recommandation/artist1", {likes: 4}, function(err,resp) {
  if ( err ) {
    console.log("Error updating the document: ",err,resp);
    return;
  }
  console.log("Document updated: ");
});