How can I programmatically create a node?
The following code will help you to save an image in a new node.
use \Drupal\node\Entity\Node;
use \Drupal\file\Entity\File;
 
// Create file object from remote URL.
$data = file_get_contents('https://www.drupal.org/files/druplicon.small_.png');
$file = file_save_data($data, 'public://druplicon.png', FILE_EXISTS_REPLACE);
 
// Create node object with attached file.
$node = Node::create([
  'type'        =&gt; 'article',
  'title'       =&gt; 'Druplicon test',
  'field_image' =&gt; [
    'target_id' =&gt; $file-&gt;id(),
    'alt' =&gt; 'Hello world',
    'title' =&gt; 'Goodbye world'
  ],
]);
$node-&gt;save();