PowerWire.eu

Independent IBM i, AIX and Linux news and tech tips for Europe and beyond

  • Home
  • News
  • Technical Articles
    • IBM i
    • AIX
    • Linux
    • VIOS
  • Subscribe
  • About Us
  • Contact Us
  • Advertise with PowerWire.eu

A Weather App on IBM i

September 1, 2020 by Andy Youens 1 Comment

Back to Node.js on IBM i for this one!

In this article, we will be creating a quick weather app running on our favourite server.

Once we have this up and running, in the next couple of articles we will be enhancing it to integrate with our existing applications already running on the IBM i.

At the end of this article, we should be able to open this new app, in a browser and enter a city, in the UK, and it will return the current weather for that city.

The figure below shows this result.

Where Do We Start?

Before we get down to coding, we need to subscribe to an API service that will provide weather details for us.

For this purpose, I will use the OpenWeatherMap API to provide weather information.  You need to register for this service, but there is no charge.  Details can be found at https://openweathermap.org/guide

Once we have registered, we will get an API key, which is required before we can take advantage of this service.

Creating our Framework

For this example, we will be using the NodeJS Express framework to give us a starting point.

In a PASE shell, we take these steps:

  1. Npm install –save express
  2. Npm install express-generator
  3. Express weather –view pug
  4. Cd into /weather
  5. Npm install
  6. Npm start

To test all is working, point our browser to http://your-ibmi:3000

Now we can start coding our new application.

We will replace the Index.js and index.pug files to suit our requirements.  Let me start with the index.pug file, our application display file, for a better understanding.

The index.pug file will be used to ask the user to input a city in the UK and then display the results, so it will be used for both the GET and POST HTML operations.

The coding for this file is explained below.

That is all that is needed to ask the user to enter a city and return the weather results.

Next, we must change the index.js file. 

This file will have two sections, the HTML GET, used for inputting the city, and a HTML POST to call the weather API and show the subsequent results.

The coding in the figure below, explains the steps we need.

Next, we move onto the steps we must complete to show the user the weather for the location they input.

In the index.js add a POST section.

As we used the existing index.js and index.pug files, there was no need to make any changes to the Express main router app.js.

Just point your browser to your IBM using port 4000 and away we go.

Source

If you require a copy of the source I have generated for this application, it can be found on our GitHub repository.  This can be found at https://github.com/AndyYouens/f_Weather

If you can make any enhancements to this, great, put in a pull request.  That’s what open source is all about.

Conclusion

How easy was that to add a couple of lines to our Express framework and have a fully fledged weather application up and running.

Now we have our basic application, we will enhance it over the next few articles.

If you have any questions, either on this article, or any other open source, use the comments below, or send me a message on twitter @AndyYouens

Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems with over 40 years IBM midrange experience.

Filed Under: IBM i, Technical Articles

Comments

  1. k. obrien says

    September 3, 2020 at 1:05 pm

    headline typo…………………………………………………………..

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Free monthly newsletter signup

News

A screen a story – Not our problem anymore

Last week I ran into an issue, which did teach me something new about the command WRKPRB. After checking a … [Read More...]

Raspberry Pi and Machine Learning

In my last article, I demonstrated how I used Machine Learning on the Raspberry Pi to determine if a … [Read More...]

Shield Advanced Solutions – new Messaging and Monitoring solutions

September 2022 – Toronto As Shield Advanced Solutions celebrates the significant milestone, 25 years of … [Read More...]

More articles from this section

Quick Links

  • Advertise
  • Subscribe

Follow Us…

  • Email
  • LinkedIn
  • Twitter

Search This Website

Copyright © 2023 · Cue Communications · All Rights Reserved

Log in