Dependency injection to load node data
The controller base class provides the method entityTypeManager() which gets the service with the same name from the container the first time you use it. You can use this service to get the node storage:

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


and then load the node:

  $node = $node_storage-&gt;load($nid);