how to know if the page i am on is a node or not with a custom module, in drupal 8, how can I test whether I am on a node entity or not, when i browse to that page?

If I do this  $node = \Drupal::routeMatch()->getParameter('node');  I get an error if i'm not on a node.
You can do:

if(\Drupal::routeMatch()-&gt;getRouteName() == 'entity.node.canonical'){
 //Do what you want.
}