Dror Aharon
Dror Aharon

Reputation: 153

Node.js nano library for couchdb: timeout needed

I've been working with the nano library, and found myself with a need for having timeouts for my couchdb requests.

I'm using db.search/db.get/db.destroy/db.insert and as far as I could tell from the documentation there's no easy way to add a timeout.

These are async functions that pass a callback as a parameter. Ideally I would prefer not to modify the callbacks, but i'm open to suggestions.

Upvotes: 2

Views: 664

Answers (1)

dscape
dscape

Reputation: 2526

When using nano you can provide a object that is passed to the request object:

var db = require('nano')({"requestDefaults" : { "proxy" : "http://someproxy" }});

For example, that sets a proxy to http://someproxy.

To change the timeout, you can use the timeout property

This code should work:

var db = require('nano')({
  "uri": "http://localhost:5984/mydb",
  "requestDefaults" : { "timeout" : "100" } // in miliseconds
});

The default timeout in linux is about 20000ms, 20 seconds.

Upvotes: 4

Related Questions