初学者问题。
下面是在摇篮CouchDB文档中给出的一个示例:https://github.com/cloudhead/cradle
什么是http://living-room.couch
什么是5984?
new(cradle.Connection)('http://living-room.couch', 5984, {
cache: true,
raw: false
});我正在尝试从我的couchdb获取信息:
网址: subdomain.mywebsite.com
节点端口: 12345
couchdb端口: 67891
我使用上面的代码尝试了不同的连接方式,但是我得到了下面的错误。
连接的正确方式是什么?
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...发布于 2011-05-17 23:21:03
来自您发布链接的同一文档,但仅在此JS文件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;
}
});因此,它接受您给出的任何参数,并将其分割成一个数组。
5984是什么?
正如我分享的这段代码片段所示,它是要连接的端口。
它实际上接受三种类型的参数:端口号(长度在2到5位之间)、字符串和用于配置的对象。
您可以只提供一个对象,并将其各部分声明为:
new(cradle.Connection)({
host: 'http://living-room.couch',
port: 67891,
cache: true,
raw: false
});它的工作原理是一样的
https://stackoverflow.com/questions/6032917
复制相似问题