Get path alias from NID (or node object)
To get the path for a node id use AliasManager::getAliasByPath:
Drupal 8
$alias = \Drupal::service('path.alias_manager')-&gt;getAliasByPath('/node/'.$nid);

As per the new change record in Drupal 8.8.0 and above path.alias_manager is deprecated and path_alias.manager is introduced.
New syntax is as follows :
$url_alias = \Drupal::service('path_alias.manager')-&gt;getAliasByPath('/node/'. $nid, $langcode);