Read the statement by Michael Teeuw here.
"Require is not defined" Error
-
I have been trying create module can cant not get rid of this error
Uncaught ReferenceError: require is not defined
I have very little experience with node, so sorry if this has been asked a lot.
getData: function(){ var self = this; const dataRequest = require('https'); const options = { "method": "POST", "hostname": "", "port": null, "path": "", "headers": { "content-type": "application/json", "clientsecret": "", "clientid": "", "x-rapidapi-key": "", "x-rapidapi-host": "", "useQueryString": true } }; const req = dataRequest.request(options, function (res) { const chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function () { const body = Buffer.concat(chunks); console.log(body.toString()); }); });
I would use something else but the API I am trying to use shows this as an example, and I am not the best with web calls. I don’t know if this is need but the API returns as json.
-
@wn u cannot require in the web side. u might be able to load the script thru getScripts()
otherwise u have to move that to the node_helper.js
-
@wn also, you should not request/fetch IN getDom()… getDom() should ONLY format data already received…
so you can start a routine with a timer, or some such, and when it produces data, save the data pointer somewhere, and then call updateDom() which informs MM that new content is available from your module…
MM will then call getDom() to get the updated content to display