I created a module that receives the node ID from the form. On form validation, it needs to verify a node with that node ID exists.
How can I verify it?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityYou can pass the nid to \Drupal\node\Entity\Node::load(). It will return an object if it exists, NULL if it doesn't.
If you don't want to load the entire node then you can use entity query:
$values = \Drupal::entityQuery('node')->condition('nid', $id)->execute();
$node_exists = !empty($values);
This will be much more efficient because it only asks for the ids and not all the node fields.