Drupal - How can I get the node ID from a path alias?

I'm not sure if there's a direct function, but one route is to use the path alias manager service to lookup the internal path then regex it for a valid node id to perform an object load on:

$path = \Drupal::service('path.alias_manager')->getPathByAlias('/this-is-the-alias');
if(preg_match('/node\/(\d+)/', $path, $matches)) {
  $node = \Drupal\node\Entity\Node::load($matches[1]);
}

You can use the following code to get and load an entity and have access to its values.

  use \Drupal\Core\Url;

  $alias = \Drupal::service('path.alias_manager')->getPathByAlias('/etapes-de-la-vie');

  $params = Url::fromUri("internal:" . $alias)->getRouteParameters();
  $entity_type = key($params);
  $node = \Drupal::entityTypeManager()->getStorage($entity_type)->load($params[$entity_type]);
  //to use dpm you need the devel module
  dpm($node->nid->value);

References

  • Drupal 8: get entity object given system path?

Install the devel module and then use the devel toolbar item Current route info.

This results in this url, which you can type in directly and provide any path known to your drupal installation as query parameter:

/devel/routes/item?path=alias

When it is a node you find the node id in the raw parameters at the end of the listed route variables.