where to put addCommand when implement ajax callback commands
You put it in a controller like shown in the linked question, not the answers. Then this topic might be helpful how to trigger the ajax controller: How to Trigger Existing, Non-Form Ajax from JavaScript Event

For passing the node ID to the controller use a route parameter:

myModule.myRoute:
  path: '/myajax/node/{node_id}'
  defaults:
    _controller: '\Drupal\myModule\MyController::getNode'
    _title: 'Node'
  requirements:
    _permission: 'access content'


Now you can add the node ID to the endpoint url

var url = '/myajax/node/' + node_id;
Drupal.ajax({url: url}).execute();


and received it by the controller:

public function getNode($node_id) {