Nano is now part of Apache CouchDB. Repo moved to https://GitHub.com/apache/couchdb-nano

Related tags

Database nano
Overview

ByChatTestsCoverageDependenciesNPM

nano

minimalistic couchdb driver for node.js

nano features:

  • minimalistic - there is only a minimum of abstraction between you and couchdb
  • pipes - proxy requests from couchdb directly to your end user
  • errors - errors are proxied directly from couchdb: if you know couchdb you already know nano.

installation

  1. install npm
  2. npm install nano

table of contents

getting started

to use nano you need to connect it to your couchdb install, to do that:

var nano = require('nano')('http://localhost:5984');

to create a new database:

nano.db.create('alice');

and to use it:

var alice = nano.db.use('alice');

in this examples we didn't specify a callback function, the absence of a callback means "do this, ignore what happens". in nano the callback function receives always three arguments:

  • err - the error, if any
  • body - the http response body from couchdb, if no error. json parsed body, binary for non json responses
  • header - the http response header from couchdb, if no error

a simple but complete example using callbacks is:

var nano = require('nano')('http://localhost:5984');

// clean up the database we created previously
nano.db.destroy('alice', function() {
  // create a new database
  nano.db.create('alice', function() {
    // specify the database we are going to use
    var alice = nano.use('alice');
    // and insert a document in it
    alice.insert({ crazy: true }, 'rabbit', function(err, body, header) {
      if (err) {
        console.log('[alice.insert] ', err.message);
        return;
      }
      console.log('you have inserted the rabbit.')
      console.log(body);
    });
  });
});

if you run this example(after starting couchdb) you will see:

you have inserted the rabbit.
{ ok: true,
  id: 'rabbit',
  rev: '1-6e4cb465d49c0368ac3946506d26335d' }

you can also see your document in futon.

configuration

configuring nano to use your database server is as simple as:

var nano   = require('nano')('http://localhost:5984')
  , db     = nano.use('foo')
  ;

however if you don't need to instrument database objects you can simply:

// nano parses the url and knows this is a database
var db = require('nano')('http://localhost:5984/foo');

you can also pass options to the require:

// nano parses the url and knows this is a database
var db = require('nano')('http://localhost:5984/foo');

to specify further configuration options you can pass an object literal instead:

// nano parses the url and knows this is a database
var db = require('nano')(
  { "url"             : "http://localhost:5984/foo"
  , "requestDefaults" : { "proxy" : "http://someproxy" }
  , "log"             : function (id, args) {
      console.log(id, args);
    }
  });

Please check request for more information on the defaults. They support features like cookie jar, proxies, ssl, etc.

You can tell nano to not parse the url (maybe the server is behind a proxy, is accessed through a rewrite rule or other):

// nano does not parse the url and return the server api
// "http://localhost:5984/prefix" is the CouchDB server root
var couch = require('nano')(
  { "url"      : "http://localhost:5984/prefix"
    "parseUrl" : false
  });
var db = couch.use('foo');

pool size and open sockets

a very important configuration parameter if you have a high traffic website and are using nano is setting up the pool.size. by default, the node.js http global agent (client) has a certain size of active connections that can run simultaneously, while others are kept in a queue. pooling can be disabled by setting the agent property in requestDefaults to false, or adjust the global pool size using:

http.globalAgent.maxSockets = 20;

you can also increase the size in your calling context using requestDefaults if this is problematic. refer to the request documentation and examples for further clarification.

here's an example explicitly using the keep alive agent (installed using npm install agentkeepalive), especially useful to limit your open sockets when doing high-volume access to couchdb on localhost:

var agentkeepalive = require('agentkeepalive');
var myagent = new agentkeepalive({
    maxSockets: 50
  , maxKeepAliveRequests: 0
  , maxKeepAliveTime: 30000
  });

var db = require('nano')(
  { "url"              : "http://localhost:5984/foo"
  , "requestDefaults" : { "agent" : myagent }
  });

database functions

nano.db.create(name, [callback])

creates a couchdb database with the given name.

nano.db.create('alice', function(err, body) {
  if (!err) {
    console.log('database alice created!');
  }
});

nano.db.get(name, [callback])

get informations about name.

nano.db.get('alice', function(err, body) {
  if (!err) {
    console.log(body);
  }
});

nano.db.destroy(name, [callback])

destroys name.

nano.db.destroy('alice');

even though this examples looks sync it is an async function.

nano.db.list([callback])

lists all the databases in couchdb

nano.db.list(function(err, body) {
  // body is an array
  body.forEach(function(db) {
    console.log(db);
  });
});

nano.db.compact(name, [designname], [callback])

compacts name, if designname is specified also compacts its views.

nano.db.replicate(source, target, [opts], [callback])

replicates source on target with options opts. target has to exist, add create_target:true to opts to create it prior to replication.

nano.db.replicate('alice', 'http://admin:[email protected]:5984/alice',
                  { create_target:true }, function(err, body) {
    if (!err)
      console.log(body);
});

nano.db.changes(name, [params], [callback])

asks for the changes feed of name, params contains additions to the query string.

nano.db.changes('alice', function(err, body) {
  if (!err) {
    console.log(body);
  }
});

nano.db.follow(name, [params], [callback])

Uses Follow to create a solid changes feed. please consult follow documentation for more information as this is a very complete API on it's own.

var feed = db.follow({since: "now"});
feed.on('change', function (change) {
  console.log("change: ", change);
});
feed.follow();
process.nextTick(function () {
  db.insert({"bar": "baz"}, "bar");
});

nano.db.info([callback])

gets database information.

nano.db.info(function(err, body) { if (!err) { console.log('got database info'', body); } });

nano.use(name)

creates a scope where you operate inside name.

var alice = nano.use('alice');
alice.insert({ crazy: true }, 'rabbit', function(err, body) {
  // do something
});

nano.db.use(name)

alias for nano.use

nano.db.scope(name)

alias for nano.use

nano.scope(name)

alias for nano.use

nano.request(opts, [callback])

makes a request to couchdb, the available opts are:

  • opts.db – the database name
  • opts.method – the http method, defaults to get
  • opts.path – the full path of the request, overrides opts.doc and opts.att
  • opts.doc – the document name
  • opts.att – the attachment name
  • opts.qs – query string parameters, appended after any existing opts.path, opts.doc, or opts.att
  • opts.content_type – the content type of the request, default to json
  • opts.headers – additional http headers, overrides existing ones
  • opts.body – the document or attachment body
  • opts.encoding – the encoding for attachments
  • opts.multipart – array of objects for multipart request

nano.relax(opts, [callback])

alias for nano.request

nano.dinosaur(opts, [callback])

alias for nano.request

                _
              / '_)  WAT U SAY!
     _.----._/  /
    /          /
  _/  (   | ( |
 /__.-|_|--|_l

nano.config

an object containing the nano configurations, possible keys are:

  • url - the couchdb url
  • db - the database name

nano.updates([params], [callback])

listen to db updates, the available params are:

  • params.feed – Type of feed. Can be one of
  • longpoll: Closes the connection after the first event.
  • continuous: Send a line of JSON per event. Keeps the socket open until timeout.
  • eventsource: Like, continuous, but sends the events in EventSource format.
  • params.timeout – Number of seconds until CouchDB closes the connection. Default is 60.
  • params.heartbeat – Whether CouchDB will send a newline character (\n) on timeout. Default is true.

nano.followUpdates([params], [callback])

** changed in version 6 **

Use Follow to create a solid _db_updates feed. Please consult follow documentation for more information as this is a very complete api on it's own

var feed = nano.followUpdates({since: "now"});
feed.on('change', function (change) {
  console.log("change: ", change);
});
feed.follow();
process.nextTick(function () {
  nano.db.create('alice');
});

document functions

db.insert(doc, [params], [callback])

inserts doc in the database with optional params. if params is a string, its assumed as the intended document name. if params is an object, its passed as query string parameters and docName is checked for defining the document name.

var alice = nano.use('alice');
alice.insert({ crazy: true }, 'rabbit', function(err, body) {
  if (!err)
    console.log(body);
});

The insert function can also be used with the method signature db.insert(doc,[callback]), where the doc contains the _id field e.g.

var alice = nano.use('alice')
alice.insert({ _id: 'myid', crazy: true }, function(err, body) {
  if (!err)
    console.log(body)
})

and also used to update an existing document, by including the _rev token in the document being saved:

var alice = nano.use('alice')
alice.insert({ _id: 'myid', _rev: '1-23202479633c2b380f79507a776743d5', crazy: false }, function(err, body) {
  if (!err)
    console.log(body)
})

db.destroy(docname, rev, [callback])

removes revision rev of docname from couchdb.

alice.destroy('rabbit', '3-66c01cdf99e84c83a9b3fe65b88db8c0', function(err, body) {
  if (!err)
    console.log(body);
});

db.get(docname, [params], [callback])

gets docname from the database with optional query string additions params.

alice.get('rabbit', { revs_info: true }, function(err, body) {
  if (!err)
    console.log(body);
});

db.head(docname, [callback])

same as get but lightweight version that returns headers only.

alice.head('rabbit', function(err, _, headers) {
  if (!err)
    console.log(headers);
});

db.copy(src_doc, dest_doc, opts, [callback])

copy the contents (and attachments) of a document to a new document, or overwrite an existing target document

alice.copy('rabbit', 'rabbit2', { overwrite: true }, function(err, _, headers) {
  if (!err)
    console.log(headers);
});

db.bulk(docs, [params], [callback])

bulk operations(update/delete/insert) on the database, refer to the couchdb doc.

db.list([params], [callback])

list all the docs in the database with optional query string additions params. This is useful for searching.

alice.list({startkey:'cat', limit:3}, function(err, body) {
  if (!err) {
    body.rows.forEach(function(doc) {
      console.log(doc);
    });
  }
});

For a full list of params, see couchdb doc.

db.fetch(docnames, [params], [callback])

bulk fetch of the database documents, docnames are specified as per couchdb doc. additional query string params can be specified, include_docs is always set to true.

db.fetchRevs(docnames, [params], [callback])

** changed in version 6 **

bulk fetch of the revisions of the database documents, docnames are specified as per couchdb doc. additional query string params can be specified, this is the same method as fetch but include_docs is not automatically set to true.

multipart functions

db.multipart.insert(doc, attachments, params, [callback])

inserts a doc together with attachments and params. if params is a string, its assumed as the intended document name. if params is an object, its passed as query string parameters and docName is checked for defining the document name. refer to the doc for more details. attachments must be an array of objects with name, data and content_type properties.

var fs = require('fs');

fs.readFile('rabbit.png', function(err, data) {
  if (!err) {
    alice.multipart.insert({ foo: 'bar' }, [{name: 'rabbit.png', data: data, content_type: 'image/png'}], 'mydoc', function(err, body) {
        if (!err)
          console.log(body);
    });
  }
});

db.multipart.get(docname, [params], [callback])

get docname together with its attachments via multipart/related request with optional query string additions params. refer to the doc for more details. the multipart response body is a Buffer.

alice.multipart.get('rabbit', function(err, buffer) {
  if (!err)
    console.log(buffer.toString());
});

attachments functions

db.attachment.insert(docname, attname, att, contenttype, [params], [callback])

inserts an attachment attname to docname, in most cases params.rev is required. refer to the doc for more details.

var fs = require('fs');

fs.readFile('rabbit.png', function(err, data) {
  if (!err) {
    alice.attachment.insert('rabbit', 'rabbit.png', data, 'image/png',
      { rev: '12-150985a725ec88be471921a54ce91452' }, function(err, body) {
        if (!err)
          console.log(body);
    });
  }
});

or using pipe:

var fs = require('fs');

fs.createReadStream('rabbit.png').pipe(
    alice.attachment.insert('new', 'rab.png', null, 'image/png')
);

db.attachment.get(docname, attname, [params], [callback])

get docname's attachment attname with optional query string additions params.

var fs = require('fs');

alice.attachment.get('rabbit', 'rabbit.png', function(err, body) {
  if (!err) {
    fs.writeFile('rabbit.png', body);
  }
});

or using pipe:

var fs = require('fs');

alice.attachment.get('rabbit', 'rabbit.png').pipe(fs.createWriteStream('rabbit.png'));

db.attachment.destroy(docname, attname, [params], [callback])

changed in version 6

destroy attachment attname of docname's revision rev.

alice.attachment.destroy('rabbit', 'rabbit.png',
    {rev: '1-4701d73a08ce5c2f2983bf7c9ffd3320'}, function(err, body) {
      if (!err)
        console.log(body);
});

views and design functions

db.view(designname, viewname, [params], [callback])

calls a view of the specified design with optional query string additions params. if you're looking to filter the view results by key(s) pass an array of keys, e.g { keys: ['key1', 'key2', 'key_n'] }, as params.

alice.view('characters', 'crazy_ones', function(err, body) {
  if (!err) {
    body.rows.forEach(function(doc) {
      console.log(doc.value);
    });
  }
});

db.viewWithList(designname, viewname, listname, [params], [callback])

calls a list function feeded by the given view of the specified design document.

alice.viewWithList('characters', 'crazy_ones', 'my_list', function(err, body) {
  if (!err) {
    console.log(body);
  }
});

db.show(designname, showname, doc_id, [params], [callback])

calls a show function of the specified design for the document specified by doc_id with optional query string additions params.

alice.show('characters', 'format_doc', '3621898430', function(err, doc) {
  if (!err) {
    console.log(doc);
  }
});

take a look at the couchdb wiki for possible query paramaters and more information on show functions.

db.atomic(designname, updatename, docname, [body], [callback])

calls the design's update function with the specified doc in input.

db.atomic("update", "inplace", "foobar",
{field: "foo", value: "bar"}, function (error, response) {
  assert.equal(error, undefined, "failed to update");
  assert.equal(response.foo, "bar", "update worked");
});

Note that the data is sent in the body of the request. An example update handler follows:

"updates": {
  "in-place" : "function(doc, req) {
      var field = req.body.field;
      var value = req.body.value;
      var message = 'set '+field+' to '+value;
      doc[field] = value;
      return [doc, message];
  }"

db.search(designname, searchname, [params], [callback])

calls a view of the specified design with optional query string additions params.

alice.search('characters', 'crazy_ones', { q: 'cat' }, function(err, doc) {
  if (!err) {
    console.log(doc);
  }
});

check out the tests for a fully functioning example.

using cookie authentication

nano supports making requests using couchdb's cookie authentication functionality. there's a example in coffeescript, but essentially you just:

var nano     = require('nano')('http://localhost:5984')
  , username = 'user'
  , userpass = 'pass'
  , callback = console.log // this would normally be some callback
  , cookies  = {} // store cookies, normally redis or something
  ;

nano.auth(username, userpass, function (err, body, headers) {
  if (err) {
    return callback(err);
  }

  if (headers && headers['set-cookie']) {
    cookies[user] = headers['set-cookie'];
  }

  callback(null, "it worked");
});

reusing a cookie:

var auth = "some stored cookie"
  , callback = console.log // this would normally be some callback
  , alice = require('nano')(
    { url : 'http://localhost:5984/alice', cookie: 'AuthSession=' + auth });
  ;

alice.insert(doc, function (err, body, headers) {
  if (err) {
    return callback(err);
  }

  // change the cookie if couchdb tells us to
  if (headers && headers['set-cookie']) {
    auth = headers['set-cookie'];
  }

  callback(null, "it worked");
});

getting current session:

var nano = require('nano')({url: 'http://localhost:5984', cookie: 'AuthSession=' + auth});

nano.session(function(err, session) {
  if (err) {
    return console.log('oh noes!')
  }

  console.log('user is %s and has these roles: %j',
    session.userCtx.name, session.userCtx.roles);
});

advanced features

extending nano

nano is minimalistic but you can add your own features with nano.request(opts, callback)

for example, to create a function to retrieve a specific revision of the rabbit document:

function getrabbitrev(rev, callback) {
  nano.request({ db: 'alice',
                 doc: 'rabbit',
                 method: 'get',
                 params: { rev: rev }
               }, callback);
}

getrabbitrev('4-2e6cdc4c7e26b745c2881a24e0eeece2', function(err, body) {
  if (!err) {
    console.log(body);
  }
});

pipes

you can pipe in nano like in any other stream. for example if our rabbit document has an attachment with name picture.png (with a picture of our white rabbit, of course!) you can pipe it to a writable stream

var fs = require('fs'),
    nano = require('nano')('http://127.0.0.1:5984/');
var alice = nano.use('alice');
alice.attachment.get('rabbit', 'picture.png').pipe(fs.createWriteStream('/tmp/rabbit.png'));

then open /tmp/rabbit.png and you will see the rabbit picture.

tutorials, examples in the wild & screencasts

roadmap

check issues

tests

to run (and configure) the test suite simply:

cd nano
npm install
npm test

after adding a new test you can run it individually (with verbose output) using:

nano_env=testing node tests/doc/list.js list_doc_params

where list_doc_params is the test name.

meta

                _
              / _) roar! i'm a vegan!
       .-^^^-/ /
    __/       /
   /__.|_|-|_|     cannes est superb

(oo)--',- in caos

license

copyright 2011 nuno job <nunojob.com> (oo)--',--

licensed under the apache license, version 2.0 (the "license"); you may not use this file except in compliance with the license. you may obtain a copy of the license at

http://www.apache.org/licenses/LICENSE-2.0.html

unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "as is" basis, without warranties or conditions of any kind, either express or implied. see the license for the specific language governing permissions and limitations under the license.

Comments
  • Nano is moving to Apache CouchDB

    Nano is moving to Apache CouchDB

    Hi all committers,

    Nuno wants to donate Nano to the Apache CouchDB community. This is great news and will allow the CouchDB community to work closely with the Nano contributors to make sure Nano continues to be an excellent CouchDB library.

    For this to happen we need the below listed contributors to sign the CLA found here and email it to [email protected]. Could you also leave a comment below to let us know when you have signed it or if you have previously signed the Apache CLA.

    Thanks for your help

    • [x] @dscape
    • [ ] @oleics
    • [x] @hydrozen
    • [x] @jo
    • [x] @bjnortier
    • [x] @streunerlein
    • [x] @ierceg
    • [x] @JayBeavers
    • [x] @svnlto
    • [ ] @chesles
    • [x] @alappe
    • [x] @grrtrr
    • [ ] @boxxxie
    • [ ] Jonathan Mahoney
    • [x] @pgte
    • [x] @tobie
    • [x] @jlank
    • [x] @klaemo
    • [ ] @joshperry
    • [x] @jkrems
    • [x] @daleharvey
    • [x] @perezd
    • [x] @thiagoarrais
    • [ ] @mmalecki
    • [x] @PatrickHeneise
    • [ ] @fracek
    opened by garrensmith 26
  • [nano] Implement Support for Document Update Handlers

    [nano] Implement Support for Document Update Handlers

    Hello,

    I would like to implement support for CouchDb Document Update Handlers.

    http://wiki.apache.org/couchdb/Document_Update_Handlers

    My thoughts are implementing a new function called update_doc:

       /*
        * calls document update handler
        *
        * @param {design_name:string} design document namd
        * @param {update_name:string} update method to call
        * @param {doc_name:string} document name to update
        * @param {params:object} additions to the querystring
       */   
      function update_doc(design_name, update_name, doc_name, params, callback) {
         if(typeof params === "function") {
           callback = params;
           params = {};
         }
         var update_path = '_design/' + design_name + '/_update/' + update_name + '/' + doc_name;
         return relax({db: db_name, path: update_path, method: "PUT", params: params}, callback);
       }
    

    Then a public db alias called "update"

      public_functions.update = update_doc;
    

    usage

    This should provide the ability to easily execute atomic updates on the couchdb server:

    Document Update Handler in Design Document called my_design_doc:

    "updates": {
      "in-place" : "function(doc, req) {
          var field = req.query.field;
          var value = req.query.value;
          var message = 'set '+field+' to '+value;
          doc[field] = value;
          return [doc, message];
      }"
    }
    

    Then using nano:

    @db.update("my_design_doc", "in-place", "<doc_name>", { field: "foo", value: "bar" }, function(e,b) { console.log(b); }); 
    

    Thoughts?

    Feature Request 
    opened by twilson63 26
  • Subtle fix to query params for views

    Subtle fix to query params for views

    I found a really subtle bug when querying a view with a key that had a value of type Number. It simply passed along the value as key=123, when it should have been key="123". According to the CouchDB API, all values should be JSON encoded.

    I am submitting this as a pull request because I am not entirely sure how to write tests, and they were not all passing when I pulled locally :(

    Let me know what you think!

    Also, sorry if this is messing with formatting slightly, I am copy/pasting my changes into the Github text editor, thats probably what happened :/

    Bug 
    opened by perezd 26
  • Update doc with existing attachment

    Update doc with existing attachment

    What is right approach to update a doc with an existing attachment?

    I write the attachment (image) to a file, then update the doc by inserting and then read the image file to insert the attachment.

    Here is my code https://gist.github.com/3707656

    However, inserting the attachment fails with 409. I can assure that the right doc._id and doc._rev is supplied, but have no idea where the conflict comes from.

    Is there a better way to do that?

    opened by ghost 25
  • nano reformats my url and causes my db connection to fail

    nano reformats my url and causes my db connection to fail

    I'm using this code to access my db: var db = require('nano')('http://dbadmin:[email protected]:5984/db') but nano errors, reporting that this is the URI I used: Invalid URI "http:/admin:[email protected]:5984/jump/test" (test is the doc id I'm testing with)

    Strangely, nano seems to be stripping out a '/' and letters before 'admin'. What's up?

    opened by wamoyo 22
  • Errors are passed with message : Unspecified Error

    Errors are passed with message : Unspecified Error

    Yes, I see the fields reason, error, errid and all the rest.

    But still, I'm quite sure that it's not to the point nor any help to pass Unspecified Error on the description and on the error message...

    I'm quite sure there's a single place to fix this

    {
        message: 'Unspecified error',
        stacktrace: [
            'Error: Unspecified error',
            '    at Request._callback (D:\\....
            '    at Request.callback (D:\\...
            '    at Request.<anonymous> (native)',
            '    at Request.<anonymous> (events.js:70:17)',
            '    at Request.emit (D:\\...
            '    at Request.<anonymous> (D:\\...
            '    at Request.<anonymous> (events.js:67:17)',
            '    at Request.emit (D:\\...
            '    at IncomingMessage.<anonymous> (D:\\...
        ],
        request: {
            headers: { content-type: 'application/json', accept: 'a
            callback: Function,
            uri: 'http://localhost:5984/ua/test',
            jar: false,
            method: 'GET'
        },
        scope: 'couch',
        name: 'Error',
        status-code: 404,
        description: 'Unspecified error',
        status_code: 404,
        error: 'not_found',
        errid: 'non_200',
        arguments: undefined,
        headers: {
            cache-control: 'must-revalidate',
            content-type: 'application/json',
            status-code: 404,
            uri: 'http://localhost:5984/ua/test',
            date: 'Mon, 23 Jul 2012 20:07:22 GMT'
        },
        stack: 'Error: Unspecified error\n    at Request._callback
    
    opened by osher 20
  • [debug] hot swappable logging for verbose mode

    [debug] hot swappable logging for verbose mode

    Verbose mode can be incredibly useful for debugging even in production, instead of just throwing console.log all over the place, we could allow the caller to specify their own custom function for capturing the logs, if a user provides a transport, always pipe to it, otherwise if you're in testing mode, just have that function be console.log

    Thoughts?

    Feature Request 
    opened by perezd 17
  • db.follow breaks when couchdb is at a prefix

    db.follow breaks when couchdb is at a prefix

    var couch = nano({
        url: 'http://app.com/_couchdb',
        parseUrl: false
      });
    var db = couch.use('mydb')
    db.follow({since: 'now'}).follow()
    // throws error, because it requests `http://app.com/mydb` instead of  `http://app.com/_couchdb/mydb`
    

    Problem is in the followDb function at https://github.com/dscape/nano/blob/master/lib/nano.js#L308

    url.resolve('http://app.com/_couchdb', encodeURIComponent('mydb'));
    // returns http://app.com/mydb
    

    A simple workaround would be to assure that couchdb url always ends with a /

    url.resolve('http://app.com/_couchdb/', encodeURIComponent('mydb'));
    // returns http://app.com/_couchdb/mydb
    
    opened by gr2m 16
  • (#204) - Follow db updates

    (#204) - Follow db updates

    nano.follow_updates([params], [callback])

    uses follow to create a solid _db_updates feed. please consult follow documentation for more information as this is a very complete api on it's own

    var feed = nano.follow_updates({since: "now"});
    feed.on('change', function (change) {
      console.log("change: ", change);
    });
    feed.follow();
    process.nextTick(function () {
      nano.db.create('alice');
    });
    
    opened by jo 15
  • status-code 404 on our iriscouch when we contact it using nano, but not when using curl or a browser

    status-code 404 on our iriscouch when we contact it using nano, but not when using curl or a browser

    We are getting a status-code 404 on our iriscouch when we contact it using nano in node.js at url like this: https://adminuser:[email protected]:443/_users/_design/users/_view/aview

    It seems to redirect/work fine using curl or a browser. Everything else has been going great (~3 mos live), I suspect it's something with the nano library but its hard to contribute a solution since I'm not sure what iriscouch is doing to get us to our instance. I'd love any suggestions or if anyone has experienced something similar...

    Here is the full error we are getting:

    { [Error: couch returned 404]
      name: 'Error',
      scope: 'couch',
      status_code: 404,
      'status-code': 404,
      request: 
       { method: 'GET',
         headers: 
          { 'content-type': 'application/json',
            accept: 'application/json' },
         uri: 'https://adminuser:[email protected]:443/_users/_design/users/_view/aview',
         jar: false,
         callback: [Function] },
      headers: 
       { 'status-code': 404,
         uri: 'https://adminuser:[email protected]:443/_users/_design/users/_view/aview' },
      errid: 'non_200',
      description: 'Host not found',
      stacktrace: 
       [ 'Error: Host not found',
         '    at Request._callback (.../node_modules/nano/nano.js:298:39)',
         '    at Request.init.self.callback (.../node_modules/nano/node_modules/request/main.js:120:22)',
         '    at Request.EventEmitter.emit (events.js:91:17)',
         '    at Request.<anonymous> (.../node_modules/nano/node_modules/request/main.js:555:16)',
         '    at Request.EventEmitter.emit (events.js:88:17)',
         '    at IncomingMessage.Request.start.self.req.self.httpModule.request.buffer (.../node_modules/nano/node_modules/request/main.js:517:14)',
         '    at IncomingMessage.EventEmitter.emit (events.js:115:20)',
         '    at IncomingMessage._emitEnd (http.js:366:10)',
         '    at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:23)' ] }
    
    opened by cesine 14
  • Added .head(doc_id, cb)

    Added .head(doc_id, cb)

    Hallo,

    often it is a good thing to know if a document already exists with minimal payload. So here is the function to request the head of an document:

    nano.use('foo').head('bar', function(err, body, headers) {
      if(error) {
        // there is no document 'bar'
      } else {
        // yep, 'bar' is a document
      }
    })
    
    Feature Request Enhancement 
    opened by oleics 12
  • Attempting to return simple list of documents, small issue

    Attempting to return simple list of documents, small issue

    Hi there, I am attempting to return a small list of objects (checkins_each), but checkins_each is always returning [] an empty list even though the console.log clearly shows that a bunch of json entries are appended. How do I resolve this?

    // return data
        var checkins = nano.use(settings.COUCHDB_PREFIX+'checkins');
        var checkins_each = [];
        checkins.list(function(err, body) {
            if (!err) {
                console.log('hi proximity loop')
                body.rows.forEach(function(doc) {
                    console.log(doc.id);
                    checkins.get(doc.id, function(err,jsondoc) {
                        console.log(JSON.stringify(jsondoc));
                        if (jsondoc.profile_id != profile_id) {
                            console.log('appending checkin');
                            checkins_each.push(jsondoc);
                        }
                            
                    });
                });
                res.send({status: 'proximity', checkins: checkins_each});
            } else {
                console.log("error", err);
                res.send({status: 'fail', error: err});
                
            }
        
    
    opened by treeternity 0
  • db.fetch array of id error

    db.fetch array of id error

    Don't sure this is bug or because mine, just report call db.fetch([id1, id2, ...], { include_docs: true }) response error body is not json object, will work when call db.fetch({ keys: [id1, id2, ...]}, { include_docs: true })

    opened by ngohuunam 0
  • Example Lazy Creation of View

    Example Lazy Creation of View

    From the lazy view creation example code:

    // some more logic needed // what if design document exists but view doesnt, we cant just overwrite it // // we need a way to fectch and build on // and thats the reason why im not doing this at 5am

    I wanted to ask whether there is any other good, production-ready example for lazy view creation. Is it possible to efficiently detect view definition changes on lazy view creation to realize some kind of "Lazy view update"?

    I am new to couchdb and nano, so I don't know yet how this could be implemented in a performant way. It would be nice to have a clean and performant example for this common task.

    Thank you

    BR Marco

    opened by marco-bue 0
  •  Error: {error,emfile}

    Error: {error,emfile}

    Hi,

    I am querying 60 DBs one after the other, depend on the results from every DB, I am getting ad different DB errors, every time on different DB, sometime on one, sometime on few. I I query only 10 DBs for example, I get no errors.

    The error is:

    Error: {gen_server,call, {get_index, {couch_mrview_index, {mrst, <<142,84,225,128,226,114,69,21,204,199,179,167,78,218,217,132>>, nil,undefined, <<"shards/e0000000-ffffffff/supernodedb-3700000-3799999.1520034961">>, <<"_design/fromDoc">>,<<"javascript">>,[],false,false, {[]}, [{mrview,0,0,0, [<<"view">>], [], <<"function (doc) {\n if (doc.from) {\n emit(doc.from, null);\n }\n }">>, nil,nil,nil,false,false,[]}], nil,nil,0,0,undefined,undefined,undefined,undefined, undefined,nil}, <<"shards/e0000000-ffffffff/supernodedb-3700000-3799999.1520034961">>, <<142,84,225,128,226,114,69,21,204,199,179,167,78,218,217,132>>}}, infinity]} at Object.createErr [as create] (/home/adys/Sources/ether-super-node/node_modules/errs/lib/errs.js:97:11) at Request._callback (/home/adys/Sources/ether-super-node/node_modules/nano/lib/nano.js:248:15) at Request.self.callback (/home/adys/Sources/ether-super-node/node_modules/request/request.js:186:22) at Request.emit (events.js:160:13) at Request. (/home/adys/Sources/ether-super-node/node_modules/request/request.js:1163:10) at Request.emit (events.js:160:13) at IncomingMessage. (/home/adys/Sources/ether-super-node/node_modules/request/request.js:1085:12) at Object.onceWrapper (events.js:255:19) at IncomingMessage.emit (events.js:165:20) at endReadableNT (_stream_readable.js:1101:12) at process._tickCallback (internal/process/next_tick.js:152:19)

    Sometimes I am getting the error:

    error: Error: {error,emfile} at Request._callback (/home/adys/Sources/ether-super-node/node_modules/nano/lib/nano.js:248:15) at Request.self.callback (/home/adys/Sources/ether-super-node/node_modules/request/request.js:186:22) at Request.emit (events.js:160:13) at Request. (/home/adys/Sources/ether-super-node/node_modules/request/request.js:1163:10) at Request.emit (events.js:160:13) at IncomingMessage. (/home/adys/Sources/ether-super-node/node_modules/request/request.js:1085:12) at Object.onceWrapper (events.js:255:19) at IncomingMessage.emit (events.js:165:20) at endReadableNT (_stream_readable.js:1101:12) at process._tickCallback (internal/process/next_tick.js:152:19)

    or

    Error: {{badmatch,{error,emfile}}, {gen_server,init_it,6,[{file,"gen_server.erl"},{line,328}]}, {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]} at Object.createErr [as create] (/home/adys/Sources/ether-super-node/node_modules/errs/lib/errs.js:97:11) at Request._callback (/home/adys/Sources/ether-super-node/node_modules/nano/lib/nano.js:248:15) at Request.self.callback (/home/adys/Sources/ether-super-node/node_modules/request/request.js:186:22) at Request.emit (events.js:160:13) at Request. (/home/adys/Sources/ether-super-node/node_modules/request/request.js:1163:10) at Request.emit (events.js:160:13) at IncomingMessage. (/home/adys/Sources/ether-super-node/node_modules/request/request.js:1085:12) at Object.onceWrapper (events.js:255:19) at IncomingMessage.emit (events.js:165:20) at endReadableNT (_stream_readable.js:1101:12) at process._tickCallback (internal/process/next_tick.js:152:19)

    Thanks, Ady.

    opened by adyshimony 1
  • Error: badarg every few hours

    Error: badarg every few hours

    I am getting this error every few hours. Any idea?

    error: Error: error saveTransactionsBulkAsync : Error: badarg at /home/adys/Sources/ether-super-node/bin/indexer/src/utils/dbUtils.js:76:48 at step (/home/adys/Sources/ether-super-node/bin/indexer/src/utils/dbUtils.js:32:23) at Object.next (/home/adys/Sources/ether-super-node/bin/indexer/src/utils/dbUtils.js:13:53) at /home/adys/Sources/ether-super-node/bin/indexer/src/utils/dbUtils.js:7:71 at new Promise () at __awaiter (/home/adys/Sources/ether-super-node/bin/indexer/src/utils/dbUtils.js:3:12) at /home/adys/Sources/ether-super-node/bin/indexer/src/utils/dbUtils.js:57:36 at Request._callback (/home/adys/Sources/ether-super-node/node_modules/nano/lib/nano.js:241:7) at Request.self.callback (/home/adys/Sources/ether-super-node/node_modules/request/request.js:186:22) at Request.emit (events.js:160:13) at Request. (/home/adys/Sources/ether-super-node/node_modules/request/request.js:1163:10) at Request.emit (events.js:160:13) at IncomingMessage. (/home/adys/Sources/ether-super-node/node_modules/request/request.js:1085:12) at Object.onceWrapper (events.js:255:19) at IncomingMessage.emit (events.js:165:20) at endReadableNT (_stream_readable.js:1101:12) at process._tickCallback (internal/process/next_tick.js:152:19)

    opened by adyshimony 0
Releases(v6.1.4)
Owner
The Apache Software Foundation
The Apache Software Foundation
Remade from Catch-Word-js [https://github.com/Jortsoft/Catch-Word-js]

Author: https://github.com/Jortsoft Catch-Word-js This is very simple game catch word with JavaScript and Jquery install and run guide! download proje

Dimitri Kvachakhia 3 Jun 12, 2021
DataStax Node.js Driver for Apache Cassandra

DataStax Node.js Driver for Apache Cassandra® A modern, feature-rich and highly tunable Node.js client library for Apache Cassandra and DSE using excl

DataStax 1.2k Dec 30, 2022
Pulsar Flex is a modern Apache Pulsar client for Node.js, developed to be independent of C++.

PulsarFlex Apache Pulsar® client for Node.js Report Bug · Request Feature About the project Features Usage Contributing About PulsarFlex is a modern A

null 43 Aug 19, 2022
Bulk follow GitHub users using a NodeJS script.

Github bulk follow Getting Started Prerequisites Clone the project to your local environment: git clone [email protected]:farid-ouachrar/github-bulk-

Farid Ouachrar 3 Sep 27, 2021
GitHub User Search

GitHub User Search Deployed At https://friendly-yalow-01d498.netlify.app/ User Story As a user, I can search for users and see a paginated list of res

Matthew 6 Apr 26, 2022
A Node.js ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud.

Dittorm A Node.js ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud. Installatio

Waline 21 Dec 25, 2022
Nano: The official Apache CouchDB library for Node.js

Nano Offical Apache CouchDB library for Node.js. Features: Minimalistic - There is only a minimum of abstraction between you and CouchDB. Pipes - Prox

The Apache Software Foundation 578 Dec 24, 2022
A visualization grammar. Moved to: https://github.com/vega/vega

Vega: A Visualization Grammar Vega is a visualization grammar, a declarative format for creating and saving interactive visualization designs. With Ve

Trifacta Inc. 29 Dec 30, 2022
DEPRECATED. Zeppelin has moved to Apache. Please make pull request there

Zeppelin has moved to Apache. Zeppelin's has moved to Apache incubator. This github repository is not going to be synced to the ASF's one after 20/Mar

ZEPL 417 Dec 15, 2022
Simple, configurable part mock part proxy

Moxy Simple, configurable mock / proxy server. Table of Contents Quick start Programatic CLI Docker Docker compose Usage Programatic Via HTTP requests

Acrontum GmbH 7 Aug 12, 2022
nest연습용 (w. https://github.com/seuiggi, https://github.com/okysky1121)

A progressive Node.js framework for building efficient and scalable server-side applications. Description Nest framework TypeScript starter repository

이름 2 Oct 5, 2022
The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry

Fast, reliable, and secure dependency management. Fast: Yarn caches every package it has downloaded, so it never needs to download the same package ag

Yarn 41k Jan 5, 2023
The Remix version of the fakebooks app demonstrated on https://remix.run. Check out the CRA version: https://github.com/kentcdodds/fakebooks-cra

Remix Fakebooks App This is a (very) simple implementation of the fakebooks mock app demonstrated on remix.run. There is no database, but there is an

Kent C. Dodds 61 Dec 22, 2022
GitHub starter project link: https://github.com/buildspace/waveportal-starter-project

Running React on Repl.it React is a popular JavaScript library for building user interfaces. Vite is a blazing fast frontend build tool that includes

MD Rafi Uddin 0 Jun 5, 2022
Train and test machine learning models for your Arduino Nano 33 BLE Sense in the browser.

Tiny Motion Trainer Train and test IMU based TFLite models on the Web Overview Since 2009, coders have created thousands of experiments using Chrome,

Google Creative Lab 59 Nov 21, 2022
Open Source and Embedded Nano Faucet

NanoDrop Open Source, Transparent and Embedded Nano Faucet Visit: https://nanodrop.io This project was created to help bring Nano to the masses. Fauce

Anarkrypto 30 Dec 26, 2022
Snake game using pure HTML, CSS and JavaScript with GameBoy look and feel using Nano editor

Snake game using pure HTML, CSS and JavaScript with GameBoy look and feel using Nano editor. 100% commented code in Portuguese

Gabriel Martins 2 Jul 2, 2022
A lightweight Nano Node implementation made for wallets, exchanges and other services.

About This is a Light Nano Node implementation made for Wallets, Exchanges and other services. This Node has been built to be compatible with the offi

Nano - Light Net 7 Jun 25, 2022
This Is A Simple WhatsApp Bot Mode From *DhaniGans* Repo Hope you guys Will like it Repo Updates in Every Two Days

ALIEN ALFA BOT Contact Me: Scan QR Code For Session FORK THIS BEFORE PROCEEDING Use This Button To Fork Now THINGS TO CHANGE IN HEROKU ???????????? ??

TOXIC ALIEN 15 Dec 21, 2022
This is email scheduler made using MERN. This repo contains server code, client repo is linked in readme.

Email Scheduler Client This is an email scheduler server (client in different repository). It is made using node.js/express.js. Overview User can sign

Sai Charan 2 Dec 3, 2022