RobotWebTools/rclnodejs

ROS 2 client library for Node.js, with browser integration

rclnodejs — ROS 2 for JavaScript Developers

rclnodejs is a client library that lets you build ROS 2 (Robot Operating System 2) applications using JavaScript or TypeScript, running on Node.js. ROS 2 is a framework for building robot software — it handles communication between different parts of a robot system (like sensors, controllers, and planning logic) through messages, services, and actions.

What It Does

Instead of writing robot code in C++ or Python (the traditional ROS 2 languages), you can write it in JavaScript. The library gives you APIs for:

  • Topics — publish/subscribe messaging (e.g., a sensor publishing data that other nodes listen to)
  • Services — request/response calls between nodes
  • Actions — long-running tasks with feedback and cancellation
  • Parameters — configuration values for nodes
  • Lifecycle Nodes — nodes with managed states (like "configured", "active", "shutdown")

A minimal example from the README:

import rclnodejs from 'rclnodejs';

await rclnodejs.init();
const node = new rclnodejs.Node('publisher_example_node');
const publisher = node.createPublisher('std_msgs/msg/String', 'topic');
publisher.publish(`Hello ROS 2 from rclnodejs`);
node.spin();

This creates a node that publishes a string message to a topic.

Key Capabilities

1. Bring ROS 2 to the Web

The package ships two ways to connect a browser to a ROS 2 system:

  • rclnodejs/web — a typed layer over your ROS 2 graph. You allow-list which capabilities (topics, services, actions) are exposed via a config file or CLI flags; anything not listed is rejected before reaching ROS 2. It includes a typed SDK (call, publish, subscribe, action), supports WebSocket or HTTP transports, and can export OpenAPI 3.1 schemas.
  • rosocket — a thin WebSocket gateway with zero browser dependencies (just built-in WebSocket + JSON). Best for quick prototypes.

2. Observable Subscriptions

Supports RxJS Observables for reactive message processing. You can chain operators like throttleTime(), debounceTime(), map(), and combineLatest() to build declarative pipelines for handling incoming messages.

3. Electron-based Visualization

Build desktop ROS 2 apps with Electron + Three.js, packaged for Windows/macOS/Linux via Electron Forge. The featured demo is a two-joint robotic arm with manual/automatic control.

4. Automatic Message Generation

During npm install, rclnodejs automatically generates JavaScript bindings and TypeScript declarations for every ROS 2 .msg, .srv, and .action interface in your sourced environment. If you add new ROS packages later, re-run with:

npx generate-ros-messages

Generated files go to <your-project>/node_modules/rclnodejs/generated/.

5. TypeScript Support

TypeScript declaration files are included in the package. A minimal tsconfig.json setup (with module: "NodeNext", moduleResolution: "NodeNext", target: "es2022") is all you need to use import * as rclnodejs from 'rclnodejs'.

Installation

Prerequisites:

  • Node.js version >= 20.20.2
  • ROS 2 SDK (source your ROS 2 environment first, e.g., source /opt/ros/<distro>/setup.bash)

Install with:

npm i rclnodejs

Prebuilt binaries ship for Ubuntu 22.04 (ROS 2 Humble), 24.04 (Jazzy, Kilted), and 26.04 (Lyrical) on x64 and arm64 — most installs skip compilation. Anything else builds from source. Set RCLNODEJS_FORCE_BUILD=1 to always build from source.

Performance

The README states rclnodejs is faster than rclpy (the Python client) and competitive with rclcpp (the C++ client) for both topic and service round-trips.

Companion CLI

A separate tool, rclnodejs-cli, scaffolds rclnodejs application skeletons and orchestrates launch files for multi-node setups.

License

Apache License 2.0


All information above is drawn directly from the project's README.

Related

  • Project
  • Project
  • Project
  • Project
  • Project