This function does exactly what it says, it returns the current Drupal 8 node NID that is being requested by the user. Be careful where you call it if the page is not a node it can break the website.
/** * @return string */ function _access_node_id() { $node = \Drupal::routeMatch()->getParameter('node'); return $node->id(); }