MagicMirror² DocsMagicMirror² Docs
Donate
Discord
Forum
GitHub
Donate
Discord
Forum
GitHub
  • Getting Started

    • Introduction
    • Requirements
    • Installation & Usage
    • Upgrade Guide
  • Configuration

    • Introduction
    • Autostart your MagicMirror²
    • Raspberry Specific
  • Modules

    • Introduction
    • Module Configuration
    • Default Modules

      • Alert
      • Calendar
      • Clock
      • Compliments
      • Hello World
      • News Feed
      • Update Notification
      • Weather Module
    • Animation Guide
  • Module Development

    • Introduction
    • The Core module file
    • The Node Helper
    • MagicMirror Helper Methods
    • Logger
    • Notifications
    • Weather Module Weather Provider Development
    • How to write good documentation
  • About

    • MagicMirror² Manifesto
    • Contributing Guidelines
    • Donate
    • Support
    • License

MagicMirror Helper Methods

The MagicMirror core object MM has some handy methods to help you control your and other modules. Most of the MM methods are available via the convenience methods on the Module instance.

Module selection

The only additional method available for your module, is the feature to retrieve references to other modules. This can be used to hide and show other modules.

MM.getModules()

Returns Array - An array with module instances.

To make a selection of all currently loaded module instances, run the MM.getModules() method. It will return an array with all currently loaded module instances. The returned array has a lot of filtering methods. See below for more info.

Note: This method returns an empty array if not all modules are started yet. Wait for the ALL_MODULES_STARTEDnotification.

.withClass(classnames)

classnames String or Array - The class names on which you want to filter. Returns Array - An array with module instances.

If you want to make a selection based on one or more class names, use the withClass method on a result of the MM.getModules() method. The argument of the withClass(classname) method can be an array, or space separated string.

Examples:

let modules = MM.getModules().withClass("classname");
let modules = MM.getModules().withClass("classname1 classname2");
let modules = MM.getModules().withClass(["classname1", "classname2"]);

.exceptWithClass(classnames)

classnames String or Array - The class names of the modules you want to remove from the results. Returns Array - An array with module instances.

If you to remove some modules from a selection based on a classname, use the exceptWithClass method on a result of the MM.getModules() method. The argument of the exceptWithClass(classname) method can be an array, or space separated string.

Examples:

let modules = MM.getModules().exceptWithClass("classname");
let modules = MM.getModules().exceptWithClass("classname1 classname2");
let modules = MM.getModules().exceptWithClass(["classname1", "classname2"]);

.exceptModule(module)

module Module Object - The reference to a module you want to remove from the results. Returns Array - An array with module instances.

If you to remove a specific module instance from a selection based on a classname, use the exceptWithClass method on a result of the MM.getModules() method. This can be helpful if you want to select all module instances except the instance of your module.

Examples:

let modules = MM.getModules().exceptModule(this);

Of course, you can combine all of the above filters:

Example:

let modules = MM.getModules()
  .withClass("classname1")
  .exceptWithClass("classname2")
  .exceptModule(aModule);

.enumerate(callback)

callback Function(module) - The callback run on every instance.

If you want to perform an action on all selected modules, you can use the enumerate function:

MM.getModules().enumerate(function (module) {
  Log.log(module.name);
});

Example: To hide all modules except your module instance, you could write something like:

Module.register("modulename", {
  //...
  notificationReceived: function (notification, payload, sender) {
    if (notification === "DOM_OBJECTS_CREATED") {
      MM.getModules()
        .exceptModule(this)
        .enumerate(function (module) {
          module.hide(1000, function () {
            //Module hidden.
          });
        });
    }
  },
  //...
});
Help us improve this page!
Last Updated:: 4/30/25, 8:00 PM
Prev
The Node Helper
Next
Logger