Created
November 10, 2016 07:50
-
-
Save dstyle0210/e986184a0b6a33a52a981d125df7df60 to your computer and use it in GitHub Desktop.
[node] node 에서 request을 이용해서, http을 통한 json 가져오기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| 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