Interactive Node.js command-line tool that fetches current conditions and a short forecast from the Weatherstack API, then displays the results with colorized, readable formatting.
git clone https://github.com/apilayer/world-weather-cli.git
cd world-weather-clinpm install- Sign up for the Weatherstack API to obtain an access key.
- Export the key before running the CLI (no
.envloader is used):
export WEATHERSTACK_API_KEY=your_access_key_hereOptionally, if your plan does not support forecasts (or you want to reduce API calls), skip the forecast endpoint entirely:
export WEATHERSTACK_FORCE_CURRENT=1npm start
# or, after install/link
npx world-weather- Asks for a city or location, validates non-empty input.
- Requests a 3-day forecast (
forecastendpoint). - Detects plan limits and gracefully falls back to current conditions (
currentendpoint) with a notice.
- Colorized sections via
chalkfor readability. - Displays temperatures, humidity, cloud cover, wind, pressure, visibility, UV index, precipitation, and sunrise/sunset when available.
- Clear messaging for missing API key, API errors, non-JSON responses, and empty input.
- Node.js runtime
- readline for user interaction
- node-fetch for Weatherstack HTTP calls
- chalk for colored terminal output
- Not applicable (command-line interface only)
GET http://api.weatherstack.com/forecast?access_key={YOUR_KEY}&query={CITY}&units=m&forecast_days=3&hourly=1
If the forecast endpoint is not available for your plan, the CLI switches to:
GET http://api.weatherstack.com/current?access_key={YOUR_KEY}&query={CITY}&units=m
- User runs the CLI and enters a city/location.
- CLI calls Weatherstack
forecastwith metric units. - On plan limitation, falls back to
current. - Prints current readings and (when available) the upcoming forecast.
- Prompt handling with
readline. - Weatherstack request builder using
URLSearchParams. - Forecast-first fetch with fallback to current.
- Formatting and output helpers for current and forecast data.
- Requires
WEATHERSTACK_API_KEYset in the environment. - Uses metric units (
units=m) by default. - Exits with non-zero status on missing key, empty input, or API errors.
- Add automated tests and fixtures for API responses.
- Support alternative units (imperial/US).
- Optional
.envsupport for local development. - Allow batch queries or argument-based invocation (e.g.,
world-weather "New York").
