1

I'm trying to add Jquery on my server.js. I'm using windows 8 as my server. I'm performing a AJAX call with jquery on nodejs. My server would actually load a JSON data from YAHOO. i got my port 5555

I run the commandprompt on and type

npm install jquery

Then:

node server.js

Here is my server.js

var $ = require('jquery');
var http                    = require("http")
, fs                        = require("fs")
, qs                        = require("querystring")
, port                  = 5555


var server = http.createServer(function(request, response) {

$.getJSON( 'http://query.yahooapis.com/v1/public/yql?q=select * from    yahoo.finance.historicaldata where symbol = 'AAL'&format=jsonstore://datatables.org/alltableswithkeys
    ', cbFunc);

});

function cbFunc(data){
console.log(data);
}

server.listen(port);

console.log('Server is listening to http://localhost/ on port ' + port + '...');

Anyone can help me in my problem. Thanks in advance!

Please ignore the URL because that's just a sample and its working on my YAHOO URL

2
  • 1
    Side note: sample you've shown have completely invalid Url (not necessary a reason to fail, but definitely not a good sample why particular code does not work). Commented May 28, 2015 at 2:05
  • 2
    Use request Commented May 28, 2015 at 2:41

1 Answer 1

1

npm install request

then:

var request = require('request');

request.get(myUrl, { json: true }, function(err, res) {
    // handle res data here
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.