Cradle CouchDB,cradle.Connection 函数参数是什么?

发布于 2024-11-07 18:53:23 字数 1110 浏览 4 评论 0原文

初学者问题。

下面是 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

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...

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妥活 2024-11-14 18:53:23

来自您发布链接的同一文档,但仅在此 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
});

并且它的工作原理相同

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文