参考ページ
郵便番号検索API
get_address.js
#! /usr/bin/node
// ---------------------------------------------------------------
// get_address.js
//
// Jul/31/2022
//
// ---------------------------------------------------------------
'use strict'
import * as https from "https"
import * as dotenv from "dotenv"
console.error ("*** 開始 ***")
dotenv.config()
const APPID = `${process.env.APPID}`
const code_zip = process.argv[2]
console.log(code_zip)
const url_base = 'https://map.yahooapis.jp/search/zip/V1/zipCodeSearch'
const url = url_base + "?query=" + code_zip + "&output=json"
const headers = {
"Content-Type": "application/json",
"User-Agent": "Yahoo AppID: " + APPID
}
const options = {"headers": headers}
const req = https.get(url, options, res => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', dd => {
// process.stdout.write(dd)
const dict_aa = JSON.parse (dd)
console.log(dict_aa['Feature'][0]['Property']['Address'])
console.error ("*** 終了 ***")
})
})
req.on('error', error => {
console.error(error)
})
req.end()
// ---------------------------------------------------------------
package.json
{
"type": "module"
}
.env
APPID = 'dj0zaiZpPW9NN3F****'
実行例
./get_address.js 131-8634