| ROS 2 Distro | CI Status |
|---|---|
rclnodejs is a Node.js client library for ROS 2 that provides comprehensive JavaScript and TypeScript APIs for developing ROS 2 solutions.
Key features: Topics, Services, Actions, Parameters, Lifecycle Nodes, TypeScript support, RxJS Observables, Electron integration, browser ↔ ROS 2 WebSocket bridge (rosocket), and prebuilt binaries for Linux x64/arm64.
const rclnodejs = require('rclnodejs');
rclnodejs.init().then(() => {
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 example assumes your ROS 2 environment is already sourced.
- Get started: Installation, Quick Start, Tutorials
- Reference: API Documentation, Using TypeScript, ROS 2 Interface Message Generation
- Features and examples: rosocket, Observable Subscriptions, Electron-based Visualization, Performance Benchmarks, rclnodejs-cli
- Project docs: Efficient Usage Tips, FAQ and Known Issues, Building from Scratch, Contributing
Most users only need Install from npm below. If you have cloned this repository and want to run the bundled examples, see Quick Start instead.
Before installing, building, or running rclnodejs, source your ROS 2 environment:
source /opt/ros/<distro>/setup.bashUse this path if you want to depend on rclnodejs from your own ROS 2 Node.js application.
npm i rclnodejsAfter installation, use the example at the top of this README as a minimal publisher, or continue with Quick Start to run the examples in this repository.
Use this path only if you need a branch or commit not yet published to npm. GitHub installs build from source.
npm install RobotWebTools/rclnodejs#<branch>Docker: For containerized development, see the included Dockerfile for building and testing with different ROS distributions and Node.js versions.
See the features and try the examples to get started.
rclnodejs ships with prebuilt native binaries for common Linux configurations, so most installs skip compilation.
Supported Platforms:
- Ubuntu 22.04 (Jammy) - ROS 2 Humble
- Ubuntu 24.04 (Noble) - ROS 2 Jazzy, Kilted
- Ubuntu 26.04 (Resolute) - ROS 2 Lyrical
- Architectures: x64, arm64
- Node.js: >= 20.20.2 (N-API compatible)
Installations outside this matrix automatically fall back to building from source. To force a source build even when a prebuilt binary is available:
export RCLNODEJS_FORCE_BUILD=1
npm install rclnodejsFrom a clone of this repository, after sourcing your ROS 2 environment:
- Install the repository dependencies from the project root.
npm install- Run a publisher example from this checkout.
node example/topics/publisher/publisher-example.jsMore runnable examples in example/ and step-by-step guides in tutorials/.
rclnodejs auto-generates JavaScript bindings and TypeScript declarations for every ROS 2 .msg, .srv, and .action interface available in your sourced ROS 2 environment. This happens during npm install, so in most projects you do not need to run anything by hand.
Use the generated types directly:
const rclnodejs = require('rclnodejs');
let stringMsgObject = rclnodejs.createMessageObject('std_msgs/msg/String');
stringMsgObject.data = 'hello world';If you install additional ROS packages after rclnodejs was installed, re-run the generator from your project so the new interfaces are picked up:
npx generate-ros-messagesGenerated files are written to <your-project>/node_modules/rclnodejs/generated/.
In addition to the standard ROS 2 message generation (.msg, .srv, .action), rclnodejs can also generate JavaScript message files directly from IDL (Interface Definition Language) files. This is useful for custom IDL files or when you need finer control over the generation process.
To generate messages from IDL files:
npm run generate-messages-idlTypeScript declaration files are included in the package and exposed through the types entry in package.json. In most projects, configuring your tsconfig.json is sufficient:
Then import * as rclnodejs from 'rclnodejs' works the same as the JavaScript example at the top of this README. See TypeScript demos for more.
A tiny WebSocket gateway to ROS 2 — built into
rclnodejs. New in2.0.0-beta.0.
rosocket exposes ROS 2 topics/services as plain WebSocket URLs — a
lightweight alternative to the rosbridge + roslibjs stack. Zero browser
code, one Node.js process; browsers use only built-in WebSocket + JSON,
no JavaScript library required.
npx rosocket --port 9000 --topic /chatter:std_msgs/msg/Stringconst ws = new WebSocket('ws://host:9000/topic/chatter');
ws.onmessage = (e) => console.log(JSON.parse(e.data).data);
ws.onopen = () => ws.send(JSON.stringify({ data: 'hi' }));See rosocket/README.md for the URL scheme, service calls, and the programmatic startRosocket() API.
rclnodejs supports RxJS Observable subscriptions for reactive programming with ROS 2 messages. Use operators like throttleTime(), debounceTime(), map(), and combineLatest() to build declarative message processing pipelines.
const { throttleTime, map } = require('rxjs');
const obsSub = node.createObservableSubscription(
'sensor_msgs/msg/LaserScan',
'/scan'
);
obsSub.observable
.pipe(
throttleTime(200),
map((msg) => msg.ranges)
)
.subscribe((ranges) => console.log('Ranges:', ranges.length));See the Observable Subscriptions Tutorial for more details.
Build interactive desktop ROS 2 apps with Electron + Three.js, packaged for Windows/macOS/Linux via Electron Forge. Featured demo: 🦾 manipulator — a two-joint arm with manual/automatic control.
More in demo/electron.
Benchmark results for 1000 iterations with 1024 KB messages (Ubuntu 24.04 WSL2, i7-1185G7):
| Library | Topic (ms) | Service (ms) |
|---|---|---|
| rclcpp (C++) | 168 | 627 |
| rclnodejs (Node.js) | 744 | 927 |
| rclpy (Python) | 1,618 | 15,380 |
See benchmark/README.md for the full setup and methodology.
rclnodejs-cli is a companion project providing command-line tooling for scaffolding rclnodejs application skeletons and working with launch files for multi-node orchestration.
Please read the Contributing Guide before making a pull request.
Thanks to all contributors!
This project abides by the Apache License 2.0.

{ "compilerOptions": { "module": "commonjs", "moduleResolution": "node", "target": "es2020", }, }