How to get node object from node ID
There are a few ways.

If your context allows for Dependency injection, inject the entity_type.manager service and use it like so:

$node = $this-&gt;entityTypeManager-&gt;getStorage('node')-&gt;load($nid);


If not you can still use the entity_type.manager service:

$node = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;load($nid);


If you prefer, you can use the Node class directly:

$node = \Drupal\node\Entity\Node::load($nid);