How to check if a module is enabled/disabled in magento 2

From Storev-Config-Developer-Advanced you only disable the output of a module and not the module itself. So the plugins the preferences and the event observers are still taken into consideration.
If you want to detect if a module output is disabled you can do this:

change your class constructor to provide an instance of Magento\Framework\Module\Manager as a dependency:

protected $moduleManager;
public function __construct(
    ...
    \Magento\Framework\Module\Manager $moduleManager,
    ....
) {
    ...
    $this->moduleManager = $moduleManager;
    ...
}

then you can call in your execute method this:

if ($this->moduleManager->isOutputEnabled('Vendor_Module')) {
    //the module output is enabled
} else {
    //the module output is disabled
}

you might not need the else part


You can check module status by below command:

php bin/magento module:status

You can see the list of enables modules.


You can use the method isEnabled to check if your module is enabled, if your code is enabled when you use this command below, so you can use this method to do the same check:

php bin/magento module:status

First thing, add the class into your module.

protected $moduleManager;
public function __construct(
    ...
    \Magento\Framework\Module\Manager $moduleManager,
    ....
) {
    ...
    $this->moduleManager = $moduleManager;
    ...
}

Then implement this check:

if ($this->moduleManager->isEnabled('Vendor_Module')) {
    //the module is enabled
} else {
    //the module is disabled
}