Drupal8 generate a path alias for redirection

    $path = '/node/YOURNID';
    $alias = Drupal::service('path.alias_manager')->getAliasByPath($path);
    $response = new RedirectResponse($alias);
    $response->send();
    return;
Drupal version: 


Source: https://www.drupal.org/taxonomy/term/22/feed