How do I get the entity ID when inserting a new node? How do I get the ID of the inserted entity?

I am trying to use hook_ENTITY_TYPE_presave() and hook_ENTITY_TYPE_insert(), but in neither of those I can get the entity ID.

In hook_ENTITY_TYPE_presave(), I used the following code.

 if ($entity-&gt;isNew()) {
    print $entity-&gt;id();
 }
The ID isn't available in hook_ENTITY_TYPE_presave() (pre meaning before, as in not saved so the database hasn't assigned it an ID yet), but is definitely available in hook_ENTITY_TYPE_insert().

This will work, for example:

function MODULE_node_insert(NodeInterface $node) {
  // No need to check `isNew()`; if it's in an insert hook, it's new.
  $nid = $node-&gt;id();
}