I am trying to call API from the website and print out the JSON result.
but I cannot see the result.
Any thought to figure out this problem.
Thank you.
var http = require('http');
var data_info="";
http.createServer(function (req, res) {
sendJsontoAlchemy(outputMode());
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('end\n');
}).listen(1111)
console.log('Server is on');
function sendJsontoAlchemy()
{
requestNumber = JSONRequest.post(
"http://access.alchemyapi.com/calls/text/TextGetCategory",
{
apikey: "aaaaaa",
text : "Skateboard Mens Trousers t Shirt Wooden Fence",
outputMode : json,
jsonp:outputMode//call back function.
},
function (requestNumber, value, exception) {
if (value) {
processResponse(value);
} else {
processError(exception);
}
});
}
function outputMode(response)
{
console.log("the result is =>");
console.log(JSON.stringify(response));
}
I’d suggest using the very useful module request for such things.
Example Code:
If you need to output the thing from a server you can do a request({opts}).pipe(response) inside a server instead of specifying a callback.