2

初心者の質問。

以下は、Cradle CouchDB のドキュメントに記載されている例です: https://github.com/cloudhead/cradle

http://living-room.couchとは何ですか?

5984とは?

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

私は自分のcouchdbから情報を取得しようとしています:

URL: subdomain.mywebsite.com

ノードポート: 12345

カウチデシベルポート: 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...
4

1 に答える 1

5

リンクを投稿したのと同じドキュメントからですが、この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 桁) 番号、文字列、および構成用のオブジェクトの 3 種類のパラメーターを受け入れます。

オブジェクトを 1 つだけ指定して、その一部を次のように宣言できます。

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

そしてそれは同じように動作します

于 2011-05-17T15:21:03.267 に答える