Get the ID that for the node that has been just created
If you need to alter the value of a node field right after the node has been created, you don't need that code. You just need to implement hook_ENTITY_TYPE_presave() and verify the node is new.

function mymodule_node_presave(EntityInterface $entity) {
  if ($entity-&gt;isNew()) {
    // The node has been created.
    // Access the node field using $entity.
  }
}


If then, for any reason, you need the node ID, you can access it with $entity-&gt;id().

I used hook_ENTITY_TYPE_presave(), assuming the node needs to be saved with the new field value.