In this article I will take you through part of my Node.js workshop that I presented at the UK International i Power conference in June 2019.
The workshop was called ‘From Zero to Production with Node.js’. I hope those that attended enjoyed the workshop and found it beneficial.
I also included a brief introduction into the Git source control application. This allowed the students to appreciate how easy it was to show a before and after scenario.
What is iDash?
iDash is an open source project that aims to make it easy to create dashboard pages for IBM i purposes.
We are going to use this project to add a couple of our own dashboard pages.
Note: Please note this application relies heavily on DB2 for i Services – Your IBM i will need to be up to date on the DB2 PTF group to make the most of this project.
To start we have to download the source from where it lives. We use the Git Clone command to achieve this.
The steps necessary for this are as follows;
1. Fire up a SSH connection to your IBM
2. Clone the current iDash project – git clone https://firstname.lastname@example.org/litmis/ibmidash.git
3. Change into the idash directory
4. Run Git Status, just to check all is ok
5. Follow the install instructions on the original bitbucket iDash page – Npm install
6. Install SSL certs
7. Run the iDash application – node index
These steps can be seen in the figure below.
It’s all looking good, no errors in the console, so now point your favourite browser to https://your_i:8443 where you should see the iDash home page.
Now we have the application up and running, it’s time to add a couple of our dashboards.
During my workshop, I added two new dashes, these were;
• Show your Power Server Firmware
• Show the top 10 tables that have been recommended by the Database Index advisor
The figure below shows the SQL statements for these two new dashes.
Having verified these two statements give me the results I want for the two new dashes; I now need to include them within the iDash application.
As an IDE for node development, I use Microsoft Visual Studio Code. This is a free, open source IDE. Please take note IBM 😊.
This IDE can be downloaded from the link here – give it a try, I’m sure you will be impressed (unless you’re like one of my colleagues who doesn’t think it’s a patch on Visual Studio!).
The main node page of this application is the index.js file. This has to be edited to include the above SQL statements.
This can be seen below.
This has now added the functionality, now we need the results shown in the browser.
To achieve this, we need to create two new files in the /views folder. These need to be named firmware_info.pug and index_advisor.pug, as they are highlighted in the above coding.
Think of these pug files as display files, and NO we can’t use SDA!
The coding of these files is shown below;
The are many resources for how to use, and code, pug files in Node.js, so I will leave that to you to find.
We now have our new dashes into the application.
To test, append the /firmware_info to the original URL. Our firmware information is now shown – result!
Next to test the index advisor. This time append /index_advisor to the original URL.
Note: Please note you will have to restart the node server, running in the SSH shell, to enforce your changes.
That’s all well and good, but we can’t expect our users to have to key in URLs, far too much to expect.
We need to amend the drop-down menu on the application header to show our new options.
The following lines are added to the end of the file to call our new dashes.
Now, just refresh your browser and the new dashes are shown on the header menu (No need to restart the node server for screen changes!)
If we are happy with our changes, we can now promote these back to the original project. This is what open source is all about – everyone benefits.
Hopefully in this article I’ve shown how easy it is to take an open source application, and add to its functionality.
The iDash project is a fantastic example of what can be achieved with Node.js on our IBM i. Take a look at how others have used it to call programs, access the database etc.
Hopefully, by the time you read this article, my changes have made their way into the iDash project. You have to have a go and see how easy it is.
If you have any questions, either on this article, Node.js, or any other open source, use the comments below, or send me a message on twitter @AndyYouens.
I’m looking forward to the next round of the i-UG user group meetings this year in the UK, on the 7th November 2019.
Hopefully we can all meet up again at these useful user group meetings. Full details can be found on the iUG site here.
Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems with over 39 years IBM midrange experience