Programmatically updating a node I can create a node using the following code:

$node = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;create($array);


But if I have the node ID, how can I edit a node?
You can try this code

&lt;?php
use Drupal\node\Entity\Node;

$node = Node::load($nid);
//set value for field
$node-&gt;body-&gt;value = 'body';
$node-&gt;body-&gt;format = 'full_html';
//field tag
$node-&gt;field_tags = [1];
//field image
$field_image = array(
    'target_id' =&gt; $fileID,
    'alt' =&gt; "My 'alt'",
    'title' =&gt; "My 'title'",
);
$node-&gt;field_image = $field_image;

//save to update node
$node-&gt;save();