Skip to content

Instantly share code, notes, and snippets.

@hminaya
Last active December 16, 2015 05:19
Show Gist options
  • Save hminaya/5383073 to your computer and use it in GitHub Desktop.
Save hminaya/5383073 to your computer and use it in GitHub Desktop.
get JSON api with node (server side javascript)
var http = require('http');
var url = 'http://www.emplea.do/jobs.json';
http.get(url, function(res) {
var body = '';
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
var result = JSON.parse(body)
console.log(result);
});
}).on('error', function(e) {
console.log("Error: " + e.message);
});
@xenomuta
Copy link

xenomuta commented May 1, 2013

Ya que en los ejemplos de Ruby y Python se usan librerias externas, supongo que lo justo sería esto:

var request = require('request');

request('http://www.emplea.do/jobs.json', function (err, res, body) {
  console.log(JSON.parse(body));
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment