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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ddv-telnet

v0.0.1

Published

Telnet Protocol Listener

Readme

ddv-telnet

A Telnet protocol listener for Node.js, written by Chengjiabao and licensed under a 3-clause BSD license; see LICENSE.md for the full text.

Features

  • Listen for multiple telnet clients
  • Supports "TERMINAL TYPE", "NAWS" (Window Size), "NEW ENVIRON", "COMPRESS2" (MUD compression using zlib deflate)

Usage

Install it via NPM:

npm install ddv-telnet

Now use it:


var telnet = require('ddv-telnet');
var s = telnet.createServer(function (c) {
	console.log("connected; term=%s %dx%d",
		c.term, c.windowSize[0], c.windowSize[1]);
	console.log(c.env);

	c.on('data', function (buf) {
		console.log("data:", buf.toString('ascii'));
		c.write("you said " + buf);
	});
	c.on('negotiated', function (code, buf) {
		if (code == 24) {
			console.log("TERM=%s", c.term);
		}
		console.log("negotiated", code, buf.toString('ascii'));
	});
	c.on('resize', function (width, height) {
		console.log("window size is %d x %d", width, height);
	});
	c.on('interrupt', function () {
		console.log("INTR!");
		c.end();
	});
	c.on('wont', function (opt) {
		console.log("WONT", opt);
	});
	c.on('will', function (opt) {
		console.log("WILL", opt);
	});
	c.on('close', function () {
		console.log("END!");
	});

	c.write("Hello!> ");
});

s.listen(23);

Caveats

  • There is no "urgent" or "out of band" facility in Node, so some aspects of telnet interrupt handling are not possible.
  • There is no ECHO or LINE-MODE handling at this time.
  • Some consistency checks throw errors that are not caught and may cause the server to exit in the presence of bad input.

Exports

Server(connected)

The Server constructor. Returns a derivative of the TCP Server object which you may subsequently invoke listen() upon to cause it to listen on the desired address and port.

Takes a single argument, the connection callback function. The connection function has the following prototype:

 function connected(client) {}

When a connection is established, the server will attempt to negotiate the following telnet options:

  • Terminal Type
  • Window Size
  • Environment
  • Binary mode
  • Compress 2 (MUD Compression Protocol)

Once they have all been tried, the connection callback function will be invoked.

Client is an instance of a TelnetStream object that represents the server side of the client connection.

Client "implements" the ReadableStream and WritableStream interfaces.

TelnetStream

Property: 'env'

console.log(client.env.USER);

Telnet streams provide an "env" property that holds the environmental variables sent by the client. The client must support the NEW-ENVIRON telnet option for this to be effective, and clients that do will typically only send a controlled set of variables by default (such as USER and DISPLAY).

Property: 'term'

console.log(client.term);

The "term" property holds the terminal type sent by the client, if the client supports the TERMINAL TYPE telnet option.

Property: 'windowSize'

console.log("%dx%d", client.windowSize[0], client.windowSize[1]);

Holds the negotiated window size sent by clients that support the NAWS telnet option. It is an array containing the width in the zeroth element and the height in the first element.

Event: 'close'

function () {}

The close event is emitted in response to the close event being emitted on the underlying stream; it indicates that the session is no longer established.

Event: 'data'

function (data) {}

The data event emits a Buffer containing data received from the client. This may turn into a string if setEncoding() is used, but this has not been tested at the time of writing.

Event: 'environment'

function (environment) {}

This environment event emits a hash of environmental variables that have been set (or changed). This will typically only trigger if the client supports the NEW-ENVIRON telnet option and sends an incremental update.

In most cases, the NEW-ENVIRON option will be negotiated before the server connect event fires; you can find the set of environmental variables in client.env in this case.

Event: 'interrupt'

function () {}

The interrupt event triggers when the client sents the Interrupt Processing telnet command. This is associated with the CTRL-C key by default, but may not be effective, based on the line editing mode of the client and the local TTY INTR character assignment.

Event: 'suspend'

function () {}

The interrupt event triggers when the client sents the Suspend Processing telnet command. This is associated with the CTRL-Z key by default, but may not be effective, based on the line editing mode of the client and the local TTY SUSP character assignment.

Event: 'resize'

function (width, height) {}

The resize event emits the new dimensions of the client terminal. This will fire if the client supports the NAWS (Negotiate About Window Size) telnet option.

In most cases, this will be negotiated before the server connect event fires; you can find the dimensions in the array client.windowSize.

end()

destroy()

destroySoon()

pause()

resume()

pipe(dest, opts)

setEncoding(enc)

Map to the equivalent WritableStream methods of the same names. Note that neither pipe() nor setEncoding() have been tested at the time of writing; YMMV.

write(buffer)

write(data, encoding)

Sends data to the client, just like WritableStream#write. The data will be properly encoded and formatted for the telnet stream; this is handled by the write method so you just send the data you want the client to receive.

telnetCommand(dodontwill, command)

Sends a telnet "Interpret As Command" (IAC) sequence to the client. dodontwill is one of the telnet DONT, DO, WONT, WILL command ids.

command is either a telnet option id (8-bit integer) or an array of 8-bit integers to be used as part of a sub-negotiation.

If you find that you need this method, chances are that we need to extend telnet.js; I'd love to hear about that, or better yet, see a pull request!