This is a simple Weather App built on Node.js without a GUI. It can be run via command line.
I've implemented two versions of the same app.
Callbacks Version - Executes via the traditional callback functions feature of Node.
Promise Version - Executes via Promises which have been added to core Node as part of the ES6 upgrade.
Node.js and npm
-
Clone the repo on your system locally.
-
Open a terminal at the root of the project.
-
Run
npm install
-
This will install the dependencies.
-
In the root folder, open the file
.env1
You need to edit the dummyAPI Keys
with your own API Keys .- Set
API_KEY_GEO = < Geocode API Key >
- Set
API_KEY_OWM = < Current Weather Map API Key >
You can get an OWM API Key here. (Sign up Required)
Both of these step is really important. The app won't work if you don't put valid API Keys.
- Set
-
Now rename the file from
.env1
to.env
And the app is ready.
There are (sort of) two vesions of this app. Run the following command (from root of the project, in terminal) to test the app.
node app-callbacks.js -a 'New Delhi, India'
node app-promise.js -a 'New Delhi, India'
You should get the output in folowing format for both versions -
The address that you're searching for: New Delhi, India
Location Matched: New Delhi, Delhi, India
According to OWM,
It's currently 29.00 C.
It feels like 28.80 C though.
After you've tested the app as instructed above, you can try variants of the commands given below.
Search by PIN Code
node app-callbacks.js -a 132001 // fetches result as expected
node app-callbacks.js -a 000001 // try this out :P
Search by Street Address
node app-callback.js -a 'Tagore Garden, Baldev Nagar'
Search by PIN Code
node app-promise.js -a 134007 // fetches result as expected
node app-promise.js -a 000001 // try this out :P
Search by Street Address
node app-promise.js -a 'Prayagraj'
- To set up Geocode API you'll have to set up a billing account at Google Cloud Console (as part of a project). They give 200 USD in credits every month, which is more than sufficient for the purpose of trying (and tinkering with) this app.
- There's a directory
playground
in the root of folder. It contains files that aren't related to the app but they helped in understanding the implementation of some features crucial to the app.