Using drupal 8, this is how I did (after a quick search in the pathauto.module file) :
Step 1 : Create the node
$node = Node::create([
'type' => 'article',
'title' => 'Test article',
'langcode' => 'en', // Get it however you want or hardcode it.
'uid' => [USER_ID] // Get it however you want.
Step 2 : Save the node
Step 3 : Insert the path (make sure the pathauto module is installed and add a pattern for the give node type)
If you need to update the node programmatically, don't forget to update its path :
pathauto_entity_update($node) and don't forget to delete it if you delete the node (delete it BEFORE you delete the node of course since the reference will be lost if you don't do that) :