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

nodbus-plus

v1.0.1

Published

A nodejs modbus library made in javascript

Readme

Nodbus-Plus

A Modbus protocol library for Node.js, written entirely in JavaScript. It supports both Modbus Serial and Modbus TCP.

Introduction

Nodbus-Plus is a Modbus protocol stack for Node.js. You can use its API to create your own Modbus client and server, or use its built-in client and server for quick Modbus communication in just minutes.

Installation

npm install nodbus-plus

Quick Start

Creating a Modbus Server

const nodbus = require('nodbus-plus');

// TCP server configuration (uses default values if not specified)
const cfg = {
    inputs: 2048,            // Number of discrete inputs
    coils: 2048,             // Number of coils
    holdingRegisters: 2048,  // Number of holding registers
    inputRegisters: 2048,    // Number of input registers
    port: 502                // Port on which to listen
};

let server = nodbus.createTcpServer('tcp', cfg);

The first argument specifies the transport layer type. Supported options are 'tcp', 'udp4', and 'udp6'.
To create a serial server instead, use createSerialServer:

// Serial server configuration
const cfg = {
    address: 1,                    // Modbus slave address (1–247)
    transmissionMode: 0,           // 0 = RTU, 1 = ASCII
    inputs: 2048,                  // Number of discrete inputs
    coils: 2048,                   // Number of coils
    holdingRegisters: 2048,        // Number of holding registers
    inputRegisters: 2048,          // Number of input registers
    port: 'COM1'                   // Serial port path (e.g., 'COM1' on Windows, '/dev/ttyUSB0' on Linux)
};

let server = nodbus.createSerialServer('serial', cfg);

Listen for Server Events

// Emitted when server starts listening
server.on('listening', (port) => {
    console.log('Server listening on port:', port);
});

// Emitted when a request is received from a client
server.on('request', (socket, req) => {
    console.log('Request received:', req);
});

// Emitted before sending a response to client
server.on('response', (socket, res) => {
    console.log('Response:', res);
});

// Emitted when an error occurs
server.on('error', (err) => {
    console.error('Error:', err);
});

Finally, start the server:

server.start();

Creating a Modbus Client

To create a Modbus client, use createTcpClient or createSerialClient:

const nodbus = require('nodbus-plus');

let client = nodbus.createSerialClient();

// Emitted when client establishes connection with the server
client.on('connection', (id) => {
    console.log('Connection established:', id);
});

// Emitted when an error occurs
client.on('error', (err) => {
    console.error('Error:', err);
});

// Emitted when a request is sent to server
client.on('request', (id, req) => {
    console.log('Request sent to device:', id);
});

// Emitted when a response timeout occurs
client.on('req-timeout', (id, adu) => {
    console.error('Request timeout for device:', id);
});

// Emitted when a response is received
client.on('response', (id, res) => {
    console.log('Response from device:', id, res);
});

Add channels to the client. Each channel represents a connection to a Modbus device:

// Channel configuration
const channelCfg = {
    ip: '127.0.0.1',      // Target device IP address
    port: 502,            // Target device port
    timeout: 250          // Request timeout in milliseconds
};

client.addChannel('device1', 'tcp1', channelCfg);
client.connect('device1');

Once connected, use available Modbus functions to exchange data:

// Read 2 coils starting at address 0 from device at Modbus address 1
client.readCoils('device1', 1, 0, 2);

Documentation

For comprehensive API documentation, visit the official documentation.

Getting Started

New to Nodbus-Plus? The Getting Started Guide provides installation instructions and basic usage examples.

Examples

See the ./samples directory for example programs demonstrating library usage.

Features

  • Full Modbus Protocol Support: Read/write coils, discrete inputs, holding registers, and input registers.
  • Modbus Serial (RTU/ASCII): Serial communication with RTU and ASCII transmission modes.
  • Modbus TCP: TCP/IP network communication with standard Modbus TCP protocol.
  • Pure JavaScript: No native dependencies; works on any Node.js environment.
  • Client & Server: Create both Modbus clients and servers with the same library.
  • Event-Driven: Asynchronous event-based API for responsive applications.

Contributing

Contributions are welcome! If you find a bug or have a feature suggestion, please open an issue.

License

MIT License. See LICENSE.md for details.