# Build rclnodejs ### Get ready for ROS 2 1. Install ROS 2 from binary package. ROS 2 is a cross-platform system, which covers Linux, macOS and Windows, and the `rclnodejs` module is developed against the [`master`](https://github.com/ros2/ros2/blob/master/ros2.repos) branch of ROS 2. You can download the latest binary packages from the [ROS 2 nightly builds](https://github.com/ros2/ros2/releases/tag/release-rolling-nightlies) and follow the instructions of [Linux](https://docs.ros.org/en/lyrical/Installation/Ubuntu-Install-Debians.html)/[Windows](https://docs.ros.org/en/lyrical/Installation/Windows-Install-Binary.html) to setup the environment. Supported ROS 2 distributions: Rolling, Lyrical, Kilted, Jazzy, and Humble. 2. Build ROS 2 from scratch. Alternatively, you can build ROS 2 from scratch. Please select the platform you want to work on, then reference the instructions of [Linux](https://docs.ros.org/en/lyrical/Installation/Alternatives/Ubuntu-Development-Setup.html#)/[Windows](https://docs.ros.org/en/lyrical/Installation/Alternatives/Windows-Development-Setup.html) to build ROS 2 (please build with flag `--merge-install`). ### Install `Node.js` **Notice:** `rclnodejs` requires Node.js version >= 20.20.2. I install Nodejs from either: - Node.js official [website](https://nodejs.org/en/) - Node Version Manager ([nvm](https://github.com/creationix/nvm)) ### C++ Toolchain Requirements The native addon follows the ROS 2 distro toolchain requirement: - Humble, Jazzy, and Kilted build with C++17. - Post-Kilted distros, including Lyrical and newer Rolling snapshots, build with C++20. If no prebuilt binary is available for your target, make sure your local compiler matches the required C++ standard before running `npm install`. ### Get Code Open a terminal, and input: ```bash git clone https://github.com/RobotWebTools/rclnodejs.git ``` ### Build Module Before you build the module, you should make sure the ROS2 environments were loaded. You can check if the `AMENT_PREFIX_PATH` environment variable was set: - For Windows: `echo %AMENT_PREFIX_PATH%` in the command prompt. - For Linux and macOS: `echo $AMENT_PREFIX_PATH` in the terminal. If the `AMENT_PREFIX_PATH` is unset, you should load the ROS2 environments: - For Windows, open the command prompt and run ```bash call \install\local_setup.bat ``` - For Linux and macOS, open the terminal and run: ```bash source /install/local_setup.bash ``` This `Node.js` module is built by [node-gyp](https://www.npmjs.com/package/node-gyp), all you have to do is just to run the following command: ```javascript npm install ``` **Windows-specific**: make sure a Python 3.x interpreter is available in your `PATH` before running the command, as required by [node-gyp](https://github.com/nodejs/node-gyp#on-windows). ## Run Unit Tests The test suite is implemented using the [mocha](https://www.npmjs.com/package/mocha) JavaScript test framework for node.js. Run the unit tests: ```javascript npm run test ``` **Windows-specific**: the tests requires in a `Microsoft Visual Studio Native Tools command prompt`, and also make sure Python 3.x interpreter is first searched in your `PATH` before running te test. You can change it temporarily by: ```bash set PATH=;%PATH% ```