#!/usr/bin/env node
// 필요: node 18+ (fetch 내장)
// 실행: node weather.js Seoul
const city = process.argv[2];
if (!city) {
console.error("사용법: node weather.js <city>");
process.exit(1);
}
async function getWeather(city) {
try {
const res = await fetch(`https://wttr.in/${city}?format=j1`);
const data = await res.json();
const current = data.current_condition[0];
console.log(`📍 도시: ${city}`);
console.log(`🌡️ 온도: ${current.temp_C}°C`);
console.log(`💧 습도: ${current.humidity}%`);
console.log(`🌥️ 날씨: ${current.weatherDesc[0].value}`);
} catch (err) {
console.error("에러 발생:", err.message);
}
}
getWeather(city);