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; // proce开发者_JS百科ss.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...
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
精彩评论