I work with an Amazon JSON API, in which I search the products and treat the information according to their results, but within the NodeJS the API information is written to the console, but not written in the response to the call. How to respond only after the data returned from Amazon?
Here is the code example:
var http = require("http");
//Biblioteca para conexão e pesquisa nos servidores da Amazon
var aws = require("aws-lib");
http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "application/json"});
var prodAdv = aws.createProdAdvClient(yourAccessKeyId, yourSecretAccessKey, yourAssociateTag);
var options = {SearchIndex: "Books", Keywords: "Javascript"};
var resposta = "";
prodAdv.call("ItemSearch", options, function(err, result) {
console.log(result);
resposta = result;
});
res.end(resposta);
}).listen(1337, "127.0.0.1");
PS: The parameters of the createProdAdvClient
function have been changed for security purposes, for which purpose they are all filled in.