You can use the following code to set URL alias for a node if your website also uses Pathauto
$node->path = [
'alias' => '/' . $node_url,
'pathauto' => Drupal\pathauto\PathautoState::SKIP,
];
$node->save();
Where $node_url is the desired alias and $node is loaded node object.
Disqus