How to call a controller of custom module when a node is published? I am planning to make a module whose controller is called or method in that controller executes when a node is published. The module should be able to get the title and other properties of article that is set to published. Here is controller:

namespace Drupal\my_module\Controller;

use Drupal\Core\Controller\ControllerBase;

class myController extends ControllerBase
{
    //Function that should be executed when a specific node is published
    public function publish()
    {
     //here I should get title and other properties of the published node
    }
} 


I am new to drupal, I have looked into web and found that the solution is related to hooks but I don't know how to use them. Any help regarding the issue will be appreciated.
The purpose of controllers is just providing output for a route, not implementing hooks. If you need to write code that is invoked when a node is published, you need to implement one of the following hooks:


hook_ENTITY_TYPE_presave(), invoked right before the entity is saved
hook_ENTITY_TYPE_update() (invoked after an entity is updated and saved in the database) and hook_ENTITY_TYPE_insert() (invoked after an entity is created and saved in the database)


hook_node_presave(), hook_node_update(), and hook_node_insert() get a Node object as parameter, so obtaining the body value is pretty easy.

use Drupal\node\Entity\Node;

function mymodule_node_presave(Node $node) {
  $body = $node-&gt;get('body')-&gt;value;
  $summary = $node-&gt;get('body')-&gt;summary;
}


Getting the taxonomy term from a reference field of a node can be achieved with code similar to the following one.

use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;

function mymodule_node_presave(Node $node) {
  $term = Term::load($node-&gt;get('field_tags')-&gt;target_id);
}


To that, you need to add the code to verify the node has been published.

use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;

function mymodule_node_presave(Node $node) {
  if ($node-&gt;status()) {
    // The node has been published.
    $body = $node-&gt;get('body')-&gt;value;
    $summary = $node-&gt;get('body')-&gt;summary;
    $term = Term::load($node-&gt;get('field_tags')-&gt;target_id);
    $term_name = $term-&gt;getName();
  }
}


If the taxonomy reference field is not field_tags, replace field_tags with the right machine name of the field.