Posts

Showing posts with the label httprequest

NodeJS - Return a JSON from a request

NodeJS - Return a JSON from a request I am currently doing some stuffs in NodeJS and now I have the following issue: When I get a JSON Object from a HTTP Request and want to return it, it's showing "undefined" . "undefined" Here is my not working NodeJS Code: function verifyUser(uname,pword){ var options = { url: 'CENSORED', method: 'POST', headers: headers, form: {'Username':uname, 'Password':pword, 'Key':key} } request(options,function(error,response,body){ if(!error && response.statusCode == 200){ return body; } }) } var test1 = verifyUser("RobDeFlop","CENSORED"); console.log(test1); But when I replace the return with a console.log its showing me the json object. I hope someone can help me :) return console.log The function you pass to request is called by request once the response ...