n4m : maxAPI error
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.
Have you tried to pull the maxApi library in you code? "const maxApi = require('max-api');"
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);
});
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.
Wow! You're the # one. I owe you a beer :))
I am glad I could help!