node-nntp get article fails

82 Views Asked by At

I've been trying the node-nntp examples. Although the following example works for misc.test, when trying other groups the article function fails to fetch the first article when no message id or article number is passed in. I discovered that it does work if I pass a valid article number as a parameter.

I have tried passing the high article counts as a parameter firstArticle, but this fails. I'm new to Node and Javascript so I'm not sure why this is the case. It works if I hard code the first parameter of c.article with a the same article number but obviously I'd like to pass the article numbers as parameters to get the articles.

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

var c = new NNTP();
c.on('ready', function() {
var firstArticle;
  c.group('test.group', function(err, count, low, high) {
  console.log(count);
  console.log(low);
  console.log(high);
  firstArticle = high;
    if (err) throw err;
  });
  c.article(firstArticle,function(err, n, id, headers, body) {
    console.log('firstArticle: ' + firstArticle);
    if (err) throw err;
    console.log('Article #' + n);
    console.log('Article ID: ' + id);
    console.log('Article headers: ' + inspect(headers));
    console.log('Article body: ' + inspect(body.toString()));
  });

});
c.on('error', function(err) {
  console.log('Error: ' + err);
});
c.on('close', function(had_err) {
  console.log('Connection closed');
});
c.connect({
  host: 'news,test.com',
  user: 'username',
  password: 'password'
});
0

There are 0 best solutions below