The first thing to do in order to start your node is to call rosnodejs.initNode()


initNode returns a promise that will resolve when the connection to the ROS Master has been established. It will be passed a node handle for you to use if you like, though you may also get one yourself.

.then((nodeHandle) => {
  // do stuff


.then(() => {
  let nh = rosnodejs.nh;
  // do stuff


initNode accepts a second object to provide optional overrides for default behavior. Possible overrides include

  • rosMasterUri

    • Specify the ROS Master address programmatically rather than through the ROS_MASTER_URI environment variable.


    • Automatically generate messages to use rather than using the pre-generated messages.
    • Will fall back to pre-generated messages if available.


    • An object providing logging specific overrides. See logging for more information.
  • node

    • An object providing specific overrides to the ROS node itself. See Node for more information.


Once initialized, rosnodejs will continue to run until your process is exited or rosnodejs is terminated. This can be done either through Node.js' process.exit(), SIGINT, or if it receives a shutdown request from the ROS Master. It can also be done by calling rosnodejs.shutdown().

Registering Shutdown Hooks

Shutdown hooks can be registered once the ROS node has been initialized.

rosnodejs.on('shutdown', function() {  });
rosnodejs.once('shutdown', function() {  });
rosnodejs.removeListener('shutdown', function() { });

Note: the function passed into removeListener must be the same function used when registering the listener. See

Wiki: rosnodejs/overview/Initialization and Shutdown (last edited 2017-09-05 18:06:42 by chris-smith)