How can I check if a module is enabled? In Drupal 7, you can use module_exists() to check whether a module is enabled (as well as whether it exists).

For example,

if (module_exists('devel')) {


How can you check whether a module is enabled in Drupal 8?
Just like Clive mention....

injecting the module_handlerservice would be preferable to using \Drupal (assuming it's an option in current context)

Here is an example of checking if a module is enabled using a service (without injecting it).
$moduleHandler = \Drupal::service('module_handler');
if ($moduleHandler-&gt;moduleExists('devel')) {
  // Code Here
}