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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@appliedminds/tcp

v4.1.1

Published

Service wrapper to easily integrate TCP services

Readme

TCP

tests

Easily integrate with TCP-based services and devices using Node.js.

Features:

  • Easy event management
  • Automatic connection healing
  • Asynchronous send methods
  • RegEx-based request/response handling
Contents

Requirements

  • Node 14+

Installation

npm install @appliedminds/tcp

Usage / Examples

Create a new Device for any TCP-based service.

For example, imagine a device that uses a single byte 0x01, 0x02 or 0x03 to send forward, back or stop commands, respectively:

import { Device as TCPDevice } from '@appliedminds/tcp'

class Motor {
    constructor(host) {
        this.device = new TCPDevice({ host, port: 28836 })
        this.device.on('data', this.onReceive.bind(this))
        this.device.connect()
        this.state = 'stopped'
    }
    backward() {
        this.device.send(Buffer.from([0x02]))
    }
    forward() {
        this.device.send(Buffer.from([0x01]))
    }
    onReceive(data) {
        // Cache state when the device relays its state
        this.state = data
    }
    stop() {
        this.device.send(Buffer.from([0x03]))
    }
}

API Docs

new Device({ host : String, port : Number, parser : Transform, reconnectInterval? : Number, responseTimeout? : Number, idleTimeout? : Number })

Create a new TCP client.

  • host: Hostname or IP address of device/service
  • port: TCP port of device/service
  • parser: A data parser that extends Stream.Transform (default: no parsing)
  • reconnectInterval: Seconds until reconnect attempt after disconnect or error, use 0 for no reconnects (default: 3)
  • idleTimeout: Seconds until a connection is closed for inactivity (default: 0)
  • responseTimeout: Seconds until a call to request() will automatically time out (default: 3)

Event: 'close'

Emitted when the device has been closed (either expected or unexpected)

Event: 'connect'

Emitted when a successful connection has been made.

Event: 'data'

Emitted with a Buffer when data is received from the device.

Event: 'error'

Emitted when an error is encountered.

Event: 'timeout'

Emitted when a connection or message times out (also emits error, but allows for separate behavior)

Event: 'reconnect'

Emitted when a reconnection is attempted.

device.close() : <Promise>

Manually close connection. Resolves once the connection has been closed.

device.connect() : <Promise>

Open connection to TCP service/device. Resolves when connection has been made.

device.request(command : Buffer/String, expectedResponse : String/Regex, errorResponse? : String/Regex) : <Promise>

Make a request and wait for a response.

  • command: String or buffer to send
  • expectedResponse: Regex or string indicating a successful response
  • errorResponse: Regex or string indicating an error response

The returned Promise will resolve to a list of regex tokens matching subpatterns in expectedResponse or errorResponse (or a list of length 1 if a string was supplied)

device.send(data : Buffer/String) : <Promise>

Send data to service/device.

  • data: Outgoing buffer or string

Resolves when data has been sent.

Contributing & Tests

  1. Install development dependencies: npm install
  2. Run tests: npm test

License

MIT