weather-terminal-cli
v1.0.2
Published
CLI for getting weather
Readme
Weather Terminal CLI
Command-line utility for getting the current weather by city. The app uses the OpenWeather API, stores the default city and API token locally, and prints the forecast in the terminal.
Features
- Shows current weather for a saved city.
- Saves an OpenWeather API token for future runs.
- Saves a default city for future runs.
- Allows one-off city/token override through environment variables.
- Prints weather description, temperature, feels-like temperature, humidity, and wind speed.
Requirements
- Node.js 18 or newer.
- npm.
- OpenWeather API key from
https://openweathermap.org/api.
Installation
Install dependencies:
npm installRun locally from the project directory:
node weather.jsIf the package is installed globally or linked locally, the weather command is available because package.json defines a binary entry:
npm link
weatherConfiguration
The CLI needs an OpenWeather API token before it can request weather data.
Save the token:
node weather.js -t <API_KEY>Save the default city:
node weather.js -s KyivThe saved configuration is stored in your home directory in:
weather-data.jsonThe file contains values similar to:
{
"token": "your-api-key",
"city": "Kyiv"
}Usage
Show weather for the saved city:
node weather.jsShow help:
node weather.js -hSave another default city:
node weather.js -s LondonSave another API token:
node weather.js -t <API_KEY>Override the saved city for one run:
CITY=London node weather.jsOverride the saved token for one run:
TOKEN=<API_KEY> node weather.jsOn Windows PowerShell, use:
$env:CITY="London"; node weather.js
$env:TOKEN="<API_KEY>"; node weather.jsCLI Options
| Option | Value | Description |
| --- | --- | --- |
| -h | none | Prints help information. |
| -s | city | Saves the default city. |
| -t | API key | Saves the OpenWeather API token. |
Environment Variables
| Variable | Description |
| --- | --- |
| CITY | Overrides the saved city for the current run. |
| TOKEN | Overrides the saved token for the current run. |
Project Structure
weather-terminal-cli/
├── helpers/
│ └── args.js # CLI argument parser
├── services/
│ ├── api.service.js # OpenWeather API client and icon mapping
│ ├── log.service.js # Terminal output helpers
│ └── storage.service.js # Local config storage
├── weather.js # CLI entry point
├── package.json
└── README.mdAPI
Weather data is loaded from OpenWeather Current Weather Data API:
https://api.openweathermap.org/data/2.5/weatherThe request uses:
q— city name.appid— API token.lang=ua— Ukrainian weather descriptions.units=metric— Celsius and metric wind speed.
Scripts
Run the CLI through npm:
npm startThis command executes:
node weather.jsLicense
ISC
