How to get the nid for a newly created node? If I've created a node in an install hook, how can I immediately get a reference to the nid property? It doesn't appear to be set on the entity during save.

use Drupal\node\Entity\Node;

function my_frontpage_install() {
    $node = Node::create(array(
        'type' =&gt; 'page',
        'title' =&gt; t('Welcome'),
        'body' =&gt; array(array(
            'value' =&gt; 'Hi there'
        )),
    ));

    $node-&gt;save();

    $siteConfig = \Drupal::service('config.factory')-&gt;getEditable('system.site');
    $pageConfig = $siteConfig-&gt;get('page');
    $pageConfig['front'] = 'node/' . $node-&gt;getId(); // this returns null
    $siteConfig-&gt;set('page', $pageConfig);
    $siteConfig-&gt;save();
}


I've tried variations on the theme of getId, getNid(), get('nid'), getOriginalId(), but if I dump out the node object afer saving, the nid property is clearly not set.
The nice thing about Drupal 8, is that it's object oriented, with interfaces, abstract classes etc.

This means that all entities share a lot of methods. To get the id of a node, use the id method

$nid = $node-&gt;id();


This also works for users, taxonomy terms and any other entities you create yourself or get from contrib modules modules.

For Drupal 8 development, using an IDE becomes really powerfull as it can help you with what available methods, various instances of classes has.