简体   繁体   English

无法使Nntp客户端(nodejs)工作

[英]Can't get nntp client (nodejs) working

I'm trying to post a message to a group on the usenet using the 'nntp' package for node. 我正在尝试使用节点的“ nntp”包向Usenet上的组发布消息。 I can't get the example to work, the only example that works for me is "Get a list of all newsgroups beginning with 'alt.binaries.'". 我无法使该示例正常工作,唯一适用于我的示例是“获取以'alt.binaries'开头的所有新闻组的列表”。

Code for uploading example: 上传示例代码:

var NNTP = require('nntp'),
    inspect = require('util').inspect;

var c = new NNTP();
c.on('ready', function() {
  var msg = {
    from: { name: 'Node User', email: 'user@example.com' },
    groups: 'alt.test',
    subject: 'Just testing, do not mind me',
    body: 'node.js rules!'
  };
  c.post(msg, function(err) {
    if (err) throw err;
  });
});
c.on('error', function(err) {
  console.log('Error: ' + err);
});
c.on('close', function(had_err) {
  console.log('Connection closed');
});
c.connect({
  host: 'example.org',
  user: 'foo',
  password: 'bar'
});

Host, user and password are incorrect in the snippet above, but I'm sure they are correct (I can get the other example to work with these settings). 上面的代码段中的主机,用户和密码不正确,但是我确定它们是正确的(我可以使用另一个示例来使用这些设置)。

The error I'm getting is: 我得到的错误是:

/Develop/node/Usenet/node_modules/nntp/lib/nntp.js:662
  this._debug('> ' + this._curReq.cmd + ' ' + this._curReq.params);
       ^
TypeError: Property '_debug' of object #<NNTP> is not a function

If I add a debug function to the object in c.connect I get the following error: 如果将调试函数添加到c.connect中的对象,则会出现以下错误:

/Develop/node/Usenet/node_modules/nntp/lib/nntp.js:265
        self._curReq.cb(undefined, code, retval, type);
                     ^
TypeError: Property 'cb' of object #<Object> is not a function

I'm using node v0.10.32. 我正在使用节点v0.10.32。 I hope someone can help me out. 我希望有人能帮助我。 Thanks, Rik 谢谢,瑞克

just add "debug: function(){}" on options object at connect 只需在连接的选项对象上添加“ debug:function(){}”

var c = new NNTP();

c.on('ready', function() {
    var msg = {
        from: { name: 'Node User', email: 'user@example.com' },
        groups: 'alt.test',
        subject: 'Just testing, do not mind me',
        body: 'node.js rules!'
    };

    c.post(msg, function(err) {
        if (err) throw err;
    });
});

c.on('error', function(err) {
    console.log('Error: ' + err);
});

c.on('close', function(had_err) {
    console.log('Connection closed');
});

c.connect({
    host: 'example.org',
    user: 'foo',
    password: 'bar',
    debug: function(){}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM