Programmatically create a menu link for a node
Creating a menu link programmatically in Drupal 8 and 9 is easy. You have to provide four values, link title and Uri, menu name for which you want to create a menu link, and optionally you can provide a link weight.