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

Canteen-module // Mensa-Modul

  • *** Deutsche Version darunter // German version below ***

    Hi guys,

    i tried to develop a canteen-modul, which shows the menu including the prices of our canteen. It’s based on, a website which host most canteens from different universities in germany and switzerland.
    See this link from my first try:
    But I couldn’t solve my problem with the asyncronous request yet.
    Maybe someone can help me or want to implement this modul. 🙂

    Hallo Leute,

    ich habe versucht ein Kantinen-Modul zu entwickeln, dass das Menü inklusive der Preise unserer Mensa anzeigt. Es basiert auf, einer Website, auf der die meisten Kantinen verschiedener Universitäten in Deutschland und der Schweiz untergebracht sind.
    Hier ist der Link von meinem ersten Versuch ein solches Modul zu implementieren:
    Aber ich konnte mein Problem mit der asynchronen Anfrage leider nicht lösen.
    Vielleicht kann mir jemand helfen oder möchte dieses Modul implementieren. 🙂

  • @k-0 do you have your module posted somewhere? hard to tell from just this amount of code

  • Here is my working code (console-output works…).
    The outcommented code is for the second canteen and has no relevance.

    setTimeout(function() {
    var request = require('request');
    var heute;
    if ((new Date().toISOString().substr(11,2) < 16)) {
    	 heute = new Date().toISOString().substr(0,10);
    	 heute = new Date();
    	 heute= heute.toISOString().substr(0,10);
    var cnt = 0;
      url: ''+heute+'/meals',
      json: true
    }, function(error, response, body) {
    	 console.log('\nCAFETERIA EAH am ' +  heute.substring(8,10)+ '.'+heute.substring(5,7) +'.'+heute.substring(0,4)+':');
    	if (body.length < 1){
    		console.log('Heute geschlossen!')
    	else {
    	  while (body.length > cnt) {
    		console.log(body[cnt++].prices.employees.toFixed(2) +'€');
    //var cntr = 0;
    //  url: ''+heute+'/meals',
    //  json: true
    //}, function(error, response, body) {
    //	 	if (body.length < 1){
    //		console.log('Heute geschlossen!')
    //	}
    //	else {
    //	 console.log('\nMENSA ZEISS am ' +  heute.substring(8,10)+ '.'+heute.substring(5,7) +'.'+heute.substring(0,4)+':');
    //	  while (body.length > cntr) {
    //		console.log(body[cntr].name);
    //		console.log(body[cntr++].prices.employees.toFixed(2)+ ' €');
    //	}}
    }, 6000);

    The output is:

    Z:>node curl.js

    CAFETERIA EAH am 18.11.2019:
    Backleberkäse mit Paprikasoße, Balkangemüse und 1 Beilage
    Seelachsfilet mit Remouladensoße, Pommes frites und Salat
    Orientalische Linsen-Kürbis-Birnen-Suppe mit Brötchen

  • Project Sponsor Module Developer

    Where do you put this code? You have to put require in node_helper.js, not the module js file.
    Also check the log files in the developer tools in e.g. Chrome.

  • Module Developer

    I like the module idea very much. Could help some people around here.

    So your problem is handling the asynchrous call? Is that right?
    I think, the node_helper function is ideal to help with this (at least for a beginner).
    What I would do, as someone who has his own problems with asynchronous calls:

    start function:

        start: function() {
  "Starting module: " +;
            // Set locale.
            this.sendSocketNotification("CONFIG", this.config);
            var self = this;
            setInterval(() => {
            }, self.config.updateInterval);

    in node_helper.js:

    socketNotificationReceived: function(notification, payload) {
        if (notification === 'CONFIG') {
            this.config = payload;
            self = this;
            setInterval(function () {
            },  10 * 60 * 1000);
      collectData: function () {
        request(url, function (error, response, body) {
          self.sendSocketNotification("DATA", response);

    You basically have two separate intervals: The “async call” interval in node_helper and the dom update interval in your main js.
    After the first asynchronous call you have always some data to show in the dom update interval. This data gets overwritten whenever node_helper sends a socketNotification.

    Have a look at my rather short module using an asynchronous call:

    If you upload your module on github we can have a better look at the code and make suggestions.

    Hope it helps.

  • I couldn’t find my old code (node_helper.js and module.js files) from my first attempts, but i created new files and merged the code from @lavolp3.
    Here is the github url:

    Yes, the main problem was handling the asynchrous call. But i’m pretty sure, that there are more problems. 😛

  • @k-0 said in Canteen-module // Mensa-Modul:

    the main problem was handling the asynchrous call.

    right… you should NOT do this IN the getDom() function…

    the timer should fire off this routine… and once the request() has returned, save the data in some variable,
    and THEN call updateDom(), which will cause getDom() to be called to format the data

  • Module Developer

    @k-0 Hi k-0.
    So, I liked the idea.
    So sat down and, well, basically wrote a new module 🙂
    I’ve sent a PR, let me know your comments.

    There’s still lots to do especially the readme 🙂

    And lots of things to configure.
    I can’t use the module, my studies are 10 years back, but I think there may be some people who can benefit from it so I’m interested in bringing this forward.


    • option to show the whole week
    • option to filter meals (leave out vegetarian food, LOL)


  • Module Developer


    Doesn’t look too shabby but lots of styling to be done I guess

  • Hi Dirk,

    I could test it today and I really love it! Thank you so much!


    I already updated the ReadMe and added the “€” to the price in the .njk-file.

    It would be nice to have the date in the header on which the meal refers. 😛


    EDIT: I think that a option to show the whole week is nice, especially for ppl who have only one or two meals per day. Otherwise it will be to much informations to show.

Log in to reply