n4m : maxAPI error


    Oct 15 2019 | 3:23 pm
    After a successful npm init and a mqtt module installation I'm not able to start my script and get this : ReferenceError : maxAPI is not defined I've added the npm path to File Preferences but it seems to be something else I can't handle for now. Is there some specific initialization to do in the node_modules? Any help is highly appreciated.

    • Oct 16 2019 | 1:24 pm
      Have you tried to pull the maxApi library in you code? "const maxApi = require('max-api');"
    • Oct 16 2019 | 3:05 pm
      Yes of course, here is the code
      
      const maxApi = require("max-api");
      const mqtt = require("mqtt");
      let client;
      maxAPI.addHandler("connect",(url) => {
      	client = mqtt.connect(url);
      	client.on("connect", () => {
      	maxApi.outlet("connected");
      	})
      });
      maxApi.addHandler("publish", (message) => {
      	[topic, value] = message.split(" ");
      	console.log (topic, value);
      });
    • Oct 16 2019 | 5:50 pm
      I noticed that you have maxAPI (API all caps) defined right after the "let client". I have found that syntax must be correct. Try changing it to maxApi (not all caps) and see it that fixes the error.
    • Oct 16 2019 | 7:30 pm
      Wow! You're the # one. I owe you a beer :))
    • Oct 16 2019 | 8:12 pm
      I am glad I could help!