UNPKG

weather-cli-starter

Version:

Console interface for getting weather condition

15 lines (13 loc) 549 B
import axios from 'axios'; import { getKeyValue, TOKEN_DICTIONARY } from './storage.service.js' const getWeather = async (city) => { const token = process.env.TOKEN ?? await getKeyValue(TOKEN_DICTIONARY.token); if(!token) { throw new Error('Не задан ключ API. Задайте его через команду -t [API_KEY]'); } const { data } = await axios('http://ru.api.openweathermap.org/data/2.5/weather', { params: { q: city, appid: token, lang: 'ru', units: 'metric' } }); return data; } export { getWeather };