Skip to content

Instantly share code, notes, and snippets.

@dstyle0210
Created November 10, 2016 07:50
Show Gist options
  • Select an option

  • Save dstyle0210/e986184a0b6a33a52a981d125df7df60 to your computer and use it in GitHub Desktop.

Select an option

Save dstyle0210/e986184a0b6a33a52a981d125df7df60 to your computer and use it in GitHub Desktop.
[node] node 에서 request을 이용해서, http을 통한 json 가져오기
/**
node 에서 request을 이용해서, http을 통한 json 가져오기.
*/
var fs = require('fs');
var _ = require("underscore");
var request = require("request");
var url = "가져올 JSON 경로"
request({
url: url,
json: true
}, function (error, response, JSON) {
if (!error && response.statusCode === 200) {
console.log(JSON); // Print the json response
_.each(JSON,function(item,idx){ // underscore을 이용해서 loop.
console.log(item);
fs.writeFileSync("저장될 경로(확장자포함)","item"+idx); // 파일로 내보냄.
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment