npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nntp

v0.3.1

Published

An NNTP client module for node.js

Downloads

17

Readme

Description

node-nntp is an NNTP (usenet/newsgroups) client module for node.js.

Requirements

Examples

  • Get the headers and body of the first message in 'misc.test'
    var NNTP = require('nntp'),
        inspect = require('util').inspect;

    var c = new NNTP();
    c.on('ready', function() {
      c.group('misc.test', function(err, count, low, high) {
        if (err) throw err;
      });
      c.article(function(err, n, id, headers, body) {
        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: 'example.org',
      user: 'foo',
      password: 'bar'
    });
  • Get a list of all newsgroups beginning with 'alt.binaries.'
    var NNTP = require('nntp'),
        inspect = require('util').inspect;

    var c = new NNTP();
    c.on('ready', function() {
      c.groups('alt.binaries.*', function(err, list) {
        if (err) throw err;
        console.dir(list);
      });
    });
    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'
    });
  • Post a message to alt.test:
    var NNTP = require('nntp'),
        inspect = require('util').inspect;

    var c = new NNTP();
    c.on('ready', function() {
      var msg = {
        from: { name: 'Node User', email: '[email protected]' },
        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'
    });

API

Events

  • ready() - Emitted when connection and authentication were successful.

  • close(< boolean >hadErr) - Emitted when the connection has fully closed.

  • end() - Emitted when the connection has ended.

  • error(< Error >err) - Emitted when an error occurs. In case of protocol-level errors, err contains a 'code' property that references the related NNTP response code.

Methods

  • (constructor)() - Creates and returns a new NNTP client instance.

  • connect(< object >config) - (void) - Attempts to connect to a server. Valid config properties are:

    • host - < string > - Hostname or IP address of the server. Default: 'localhost'

    • port - < integer > - Port number of the server. Default: 119

    • secure - < boolean > - Will this be a secure (TLS) connection? Default: false

    • user - < string > - Username for authentication. Default: (none)

    • password - < string > - Password for password-based user authentication. Default: (none)

    • connTimeout - < integer > - Connection timeout in milliseconds. Default: 60000

  • end() - (void) - Ends the connection with the server.

Mandatory/Common protocol commands

  • dateTime(< function >callback) - (void) - Retrieves the server's UTC date and time in YYYYMMDDHHMMSS format. callback has 2 parameters: < Error >err, < string >datetime.

  • stat([< string >which, ]< function >callback) - (void) - Retrieves the article number and message ID for the current article if which is not given or for the article whose number or message ID is what. callback has 3 parameters: < Error >err, < integer >articleNum, < string >msgID.

  • group(< string >group, < function >callback) - (void) - Sets the current newsgroup to group. callback has 4 parameters: < Error >err, < integer >estimatedArticleCount, < integer >firstArticleNum, < integer >lastArticleNum.

  • next(< function >callback) - (void) - Attempts to move to the next article in the current newsgroup. callback has 3 parameters: < Error >err, < integer >articleNum, < string >msgID.

  • prev(< function >callback) - (void) - Attempts to move to the previous article in the current newsgroup. callback has 3 parameters: < Error >err, < integer >articleNum, < string >msgID.

  • headers([< string >which, ]< function >callback) - (void) - Retrieves the headers of the current article if which is not given or for the article whose number or message ID is what. callback has 4 parameters: < Error >err, < integer >articleNum, < string >msgID, < object >headers. headers values are always arrays (of strings).

  • body([< string >which, ]< function >callback) - (void) - Retrieves the body of the current article if which is not given or for the article whose number or message ID is what. callback has 4 parameters: < Error >err, < integer >articleNum, < string >msgID, < Buffer >body.

  • article([< string >which, ]< function >callback) - (void) - Retrieves the headers and body of the current article if which is not given or for the article whose number or message ID is what. callback has 5 parameters: < Error >err, < integer >articleNum, < string >msgID, < object >headers, < Buffer >body. headers values are always arrays (of strings).

Extended protocol commands -- these may not be implemented or enabled on all servers

* Note: A filter parameter is a single (or Array of) wildcard-capable newsgroup name filter string(s) (information on the wildcard format and wildcard examples).

  • newNews(< mixed >filter, < mixed >date, [< string >time, ] < function >callback) - (void) - Retrieves the message ID of articles in group(s) matching filter on or after a date. This date can be specified with date being a Date object, or date being a 'YYYYMMDD'-formatted string and time being a 'HHMMSS'-formatted string (defaults to midnight) in UTC/GMT. callback has 2 parameters: < Error >err, < array >msgIDs.

  • groups(< mixed >filter, < function >callback) - (void) - Retrieves a list of groups matching filter. callback has 2 parameters: < Error >err, < array >groupsInfo. groupsInfo is an array of [groupName, firstArticleNum, lastArticleNum, status] rows. Valid statuses are documented here.

  • groupsDesc(< mixed >filter, < function >callback) - (void) - Retrieves a list of group descriptions matching filter. callback has 2 parameters: < Error >err, < array >groups. groups is an array of [groupName, groupDesc] rows.

  • post(< object >msg, < function >callback) - (void) - Posts the given msg (as defined below) to the current newsgroup. callback has 1 parameter: < Error >err.

    • from - < object > - Who the message is from.

    • groups - < mixed > - A single newsgroup or array of newsgroups to post this message to.

    • subject - < string > - The subject line.

    • body - < mixed > - The body content -- a string or a Buffer (will be converted to UTF-8 string).

  • For methods that return first and last article numbers, the RFC says a group is empty if one of the following is true:

    • The last article number will be one less than the first article number, and the estimated article count will be zero. This is the only time that the last article number can be less than the first article number.

    • First and last article numbers (and estimated article count where applicable) are all 0.

    • The last article number is equal to the first article number. The estimated article count might be zero or non-zero.