0

Need your help, can't figure out what's wrong with my code. Your help is much appreciated.

Firstly, I have a main index.js file where all my main code is and I want it to call another function from another file which is post.js and execute whatever I put in that file but I can't make it work. I have an error called undefined.

index.js (Main File)

var xxx = require('./post.js');

function handlepostWaterRequest(intent, session, callback) {

            var cardTitle = "Water"
            var speechOutput = "Ok!, Now watering plants!" + xxx.post;
            callback(session.attributes,
                buildSpeechletResponse(cardTitle, speechOutput, "", true)); 
}

post.js (Second File)

var ubidots = require('ubidots');
var client = ubidots.createClient('***API Key***');

module.exports = {
    post: client.auth(function () {
            var pumpData = this.getVariable('***Key***'); 
            pumpData.getValues(function (err, data) {       
                console.log("Uploading..............");
                pumpData.saveValue(0); 
            });
    })
};

How do I call the xxx.post properly and make it executable? Much thansks!

Michael
  • 23
  • 2
  • 1
    Do you have a StackTrace for the undefined error? – Tienou Sep 08 '17 at 08:07
  • No, I do not have any slacktrace for the undefined error – Michael Sep 08 '17 at 08:13
  • 2
    I'm going to assume `client.auth....` is asynchronous and/or doesn't actually return anything. In which case `xxx.post` will be undefined. To get the value from an asynchronous function you'll most likely have to change the way your code works a little. https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – Khauri Sep 08 '17 at 08:15
  • `client.auth` does not return *anything* - hence your `undefind`: (see https://github.com/ubidots/ubidots-node/blob/master/lib/client.js ) – Jamiec Sep 08 '17 at 08:22

0 Answers0