Last active
July 10, 2018 10:43
-
-
Save sudosanet/35e97fb19acb2eb81d63b4d85542eed0 to your computer and use it in GitHub Desktop.
This file contains 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
const readlineSync = require('readline-sync'); | |
const request = require('request'); | |
const url = "http://zipcloud.ibsnet.co.jp/api/search"; | |
let code = readlineSync.questionInt('郵便番号を入力してください。'); | |
request.get({ | |
uri:url, | |
qs: { | |
"zipcode":code | |
}, | |
json: true | |
}, (err, res, data)=>{ | |
if(!data.results){ | |
console.log("データがありません"); | |
return; | |
} | |
if(process.argv[2]==="json") console.log(data); | |
else{ | |
const r = data.results[0]; | |
console.log(r.address1+r.address2+r.address3); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
必須ライブラリのインストール
npm i readline-sync request
使い方
引数にjsonをつけるとjson形式で返します