MagicMirror² v2.13.0 is available! For more information about this release, check out this topic.

Custom module bases helloworld

  • Hi everyone! Now i started to use magicMirror and want to build my simple custom module to indncate somrthing (traffic load at now).
    I wrote a scrypt

    var text1 = "";
    var text2 = "";
    var text3 = "";
    var htmlpage = '';
    var request = require('request');
    var DomParser = require('dom-parser');
    var parser = new DomParser();
    var dom;
    setInterval(function() {
    request(htmlpage, function(error, response, body) {
    dom = parser.parseFromString(body);
    text1 = dom.getElementsByClassName('traffic i-bem')[0].innerHTML;
    dom = parser.parseFromString(text1);
    text2 = dom.getElementsByTagName('H1')[0].innerHTML;
    dom = parser.parseFromString(text2);
    text3 = dom.getElementsByClassName('link link_black_yes')[0].textContent });
    }, 1000);

    request and dom-parser eas intalled.
    Then i get text data string and i want to set it into the Hello world module next.

    I added my scrypt code into the module code here:

    getDom: function() {
       var wrapper = document.createElement("div");
       wrapper.innerHTML = this.config.text;
       return wrapper;

    But it doesnt work (request and parser modules). Otherwise, just counting number works well(((.

    Could not you help me, what i have to do to get my scrypt working inside helloworld module?

  • Project Sponsor Module Developer

    @roma-cezar you need to put your code into a node_helper as it is based on node dependencies. Then you can communicate via sockets between the helper and the module. you can have a look in other modules which have a node_helper file how the communication works. also you can have a look in the developer guide here

Log in to reply