1

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Dror Aharon
  • 143
  • 1
  • 1
  • 6

1 Answers1

3

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.

dscape
  • 2,506
  • 1
  • 22
  • 20