2

Beginner Question.

Below is an example given on the Cradle CouchDB documentation: https://github.com/cloudhead/cradle

What is http://living-room.couch?

What is 5984?

new(cradle.Connection)('http://living-room.couch', 5984, {
    cache: true,
    raw: false
});

I'm trying to get info from my couchdb:

url: subdomain.mywebsite.com

node port: 12345

couchdb port: 67891

I've tried different ways to connect using the above code, but I get the below error.

What is the right way to connect?

17 May 09:50:57 - [nodemon] restarting due to changes...
17 May 09:50:57 - [nodemon] ./test_couch.js


17 May 09:50:57 - [nodemon] starting node
Server running somewhere
request starting...
request starting...


node.js:181

        throw e; // process.nextTick error, or 'error' event on first tick


^
Error: ECONNREFUSED, Connection refused
    at Socket._onConnect (net.js:602:18)
    at IOWatcher.onWritable [as callback] (net.js:186:12)

17 May 09:51:05 - [nodemon] app crashed - waiting for file change before starting...
edt
  • 22,010
  • 30
  • 83
  • 118

1 Answers1

5

From the same documentation that you posted a link to, but only in the code folder here in this JS file https://github.com/cloudhead/cradle/blob/master/lib/cradle.js

cradle.Connection = function Connection(/* variable args */) {
var args = Array.prototype.slice.call(arguments),
    host, port, remote, auth, options = {};

args.forEach(function (a) {
    if (typeof(a) === 'number' || (typeof(a) === 'string' && /^\d{2,5}$/.test(a))) {
        port = parseInt(a);
    } else if (typeof(a) === 'object') {
        options = a;
        host = host || options.host;
        port = port || options.port;
        auth = options.auth;
    } else {
        host = a;
    }
});

So it takes whatever parameters you give it, and slices it into an array.

What is 5984?

It's the port to connect to, as evinced by this code snippet I shared.

It accepts really three types of parameters, a port (between 2 and 5 digits in length) number, a string, and an object for configuration.

You could supply just one object and declare the parts of it as this:

new(cradle.Connection)({
  host: 'http://living-room.couch',
  port: 67891,
  cache: true,
  raw: false
});

and it would work the same

jcolebrand
  • 15,889
  • 12
  • 75
  • 121
  • Awesome, thanks! Should the port be the one I have assigned to node.js or CouchDB? – edt May 17 '11 at 17:55
  • Since you (presumably) are configuring couch _from within node_ then I would suggest the couchdb one. However, if you were doing ninja magic and making one nodejs instance be the couch server for another nodejs, and you were mimicking the couch interface from the secondary nodejs instance, then yes, the nodejs port. But I doubt that (for many reasons). **TL;DR: couchdb** – jcolebrand May 17 '11 at 18:00
  • I'm using webfaction hosting and they had me set it up a certain way: Create what they call an "app" (in their hosting control panel) for node.js & couchdb. Create a subdirectory for each as well and assign the app. So, each app has its own subdomain and port. – edt May 17 '11 at 18:19
  • Yes, like I said in my tl;dr: **use the couchdb port you assigned in that app-host-panel-thing** – jcolebrand May 17 '11 at 18:22
  • I finally got it working! I used your code snippet, but removed the host member "host: 'http://living-room.couch'" (for some reason causes error 'doc is not defined'). – edt Jun 02 '11 at 14:13
  • Mine was an example, not the exact working copy ;) Glad you got it working. – jcolebrand Jun 02 '11 at 14:27