/weather-cli

JS CLI to consume Weather API.

Primary LanguageTypeScript

weather-cli

JS CLI to consume Weather API.

Demo image

Setup

  1. Install dependencies
$ npm i
  1. Copy .env.example file into a new one called .env.
# Unix
$ cp .env.example .env
  1. Get an API key from Weather API and write it down in WEATHER_API_KEY variable in .env file.

  2. Run CLI.

# Directly from file
$ node dist/index.js

# As CLI
# Create symbolic link. This command is just run once.
$ npm link
# After that, you can use CLI as a terminal command.
$ weather-cli

Options

  • -c, --city

Set city to look for weather information. Default: Dallas.

$ node dist/index.js -c Mexico City
$ weather-cli --city Mexico City
  • -e, --export

Export weather information as a CSV file called weather.csv. Default: false.

$ node dist/index.js -e
$ weather-cli --export
  • -f, --filename

Name for exported file. Only available when export option is set. Default: weather.csv

$ node dist/index.js -e -f my_custom_name.csv
$ weather-cli --export --filename my_custom_name.csv
  • -h, --help

Show CLI help.

$ node dist/index.js -h
$ weather-cli --help

Development

# Watch changes
$ npm run dev

# Test CLI
$ npx ts-node src/index.ts

Production

# Transpile files
$ npm run build

# Test CLI
$ node dist/index.js