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

z21-client

v1.1.1

Published

TypeScript UDP client for Roco/Fleischmann Z21 DCC command station

Readme

z21-client

npm version License: MIT TypeScript Tests codecov Node.js

z21-client is a Node.js library written in TypeScript that implements the Roco/Fleischmann Z21 DCC command station. It provides a strongly-typed, event-driven API to control locomotives and accessories, read and write CVs, and monitor system events in real time. Connection to the Z21 command station is performed over the LAN (Ethernet/UDP).


Features

  • Send and receive UDP commands to/from a Z21 command station
  • Control track power, emergency stop, turnouts, and engine functions
  • Drive engines with speed and direction
  • Read and write CVs (configuration variables)
  • Query status, serial number, and broadcast flags
  • Subscribe to feedback and status updates
  • Fully typed API for Node.js
  • Extensive unit tests

Installation

npm install z21-client

Usage Example

import { Z21Client } from "z21-client";

const z21 = new Z21Client("192.168.0.111", 21105);

z21.on("status", (status) => {
  console.log("Z21 status:", status);
});

(async () => {
  await z21.system.setTrackPowerOn();
  await z21.system.getStatus();
  z21.engines.setDriveEngine(3, 50, true); // address, speed, forward
  await z21.engines.setEngineFunctions(3, 1, "on");
  await z21.engines.cvWrite(17, 192);
  const cvResult = await z21.engines.cvRead(17);
  await z21.accessories.switchTurnout(5, true); // address 5, output 2 (true), activate (default)
})();

API

Constructor

new Z21Client(host: string, port?: number, debug?: boolean)
  • host: IP address of your Z21 (e.g. "192.168.0.111")
  • port: UDP port (default: 21105)
  • debug: Enable debug logs (default: false)

System Controller

  • system.setTrackPowerOn(): Turn track power on
  • system.setTrackPowerOff(): Turn track power off
  • system.emergencyStop(): Emergency stop
  • system.setBroadcastFlags(engine?: boolean, accessory?: boolean, feedback?: boolean): Set broadcast flags
  • system.getBroadcastFlags(): Get broadcast flags
  • system.getSerialNumber(): Get Z21 serial number
  • system.getStatus(): Get Z21 status

Engine Controller

  • engines.getEngineInfo(address: number): Request information about an engine and subscribe to updates
  • engines.setDriveEngine(address: number, speed: number, forward: boolean, engineSpeedSteps?: number): Drive an engine with speed and direction (speed steps: 14, 28, or 128)
  • engines.setEngineFunctions(address: number, functionNumber: number, state: "on" | "off" | "toggle"): Set a function state on an engine (F1-F28)
  • engines.cvRead(cv: number): Read a CV in direct mode
  • engines.cvWrite(cv: number, value: number): Write a CV in direct mode

Accessory Controller

  • accessories.switchTurnout(address: number, output?: boolean, activate?: boolean, queue?: boolean): Switch turnout/accessory

General

  • close(): Close UDP socket and logout

Events

  • "status": Z21 status updates
  • "broadcastFlags": Broadcast flags updates
  • "serialNumber": Serial number received
  • "trackPower": Track power state
  • "programmingMode": Programming mode state
  • "shortCircuit": Short circuit detected
  • "engineInfo": Engine info updates
  • "cvResult": CV read/write result
  • "accessoryInfo": Accessory/turnout info
  • "feedback": Feedback module updates ()
  • "unknownBroadcast": Unknown broadcast received
  • "error": UDP or protocol errors
  • "debug": Debug messages

TypeScript

This library is fully typed. All types and interfaces are included automatically.


Development & Testing

  • Run all tests:
    npm test
  • Run tests with coverage:
    npm run test:coverage

License

MIT


Author

Nicolas Meunier


Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.


Links