| 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, ROS 2 in the browser (typed Web SDK + thin WebSocket gateway — rclnodejs/web, 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, Web SDK guide, Tutorials
- Reference: API Documentation, ROS 2 Interface Message Generation, Using TypeScript
- Features: ROS 2 in the browser, Observable Subscriptions, Electron-based Visualization
- 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.
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 ships two ways to reach ROS 2 from the browser — pick one based on
how much glue you want to write.
-
rclnodejs/web— typed, allow-listed, curl-able ROS 2 in the browser. Aweb.jsonfile is your public API; the browser SDK typescall/publish/subscribeend-to-end from your ROS 2 message types; and every capability is also a plain HTTP endpoint —curl -X POST http://<host>/capability/call/<name>— so shell scripts, Postman, and AI-agent tool-use just work. New in2.0.0-beta.0.import { connect } from 'rclnodejs/web'; const ros = await connect('ws://host:9000/capability'); const reply = await ros.call<'example_interfaces/srv/AddTwoInts'>( '/add_two_ints', { a: '2n', b: '40n' } ); // reply.sum is typed as `${number}n`
-
rosocket— thin WebSocket gateway, zero browser dependencies (just built-inWebSocket+JSON). Best for quick prototypes androslibjs-style apps. New in2.0.0-beta.0.npx rosocket --port 9000 --topic /chatter:std_msgs/msg/String
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 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.
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/.
For custom .idl files (Interface Definition Language), this repo also exposes npm run generate-messages-idl. See docs/BUILDING.md for when you'd need it.
TypeScript 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.
- Performance — faster than
rclpyand competitive withrclcppfor both topic and service round-trips. Full benchmarks in benchmark/README.md. - Companion CLI —
rclnodejs-cliscaffolds rclnodejs application skeletons and orchestrates launch files for multi-node setups.
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", }, }