In this article I’ll show you how easy it is to get a web-site up and running on the IBM i.
No need to be an Apache expert!
Once we have this up and running, we will enhance it over the next couple of Powerwire articles.
This will include making the site secure using HTTPS, having a login page that validates against IBM i user profiles, update database records, etc.
At the end of this set of articles, I’ll upload the code to my GitHub repository for those wishing to use this code as a template for your business needs.
For our website to work, we need Node.js installed on our IBM i.
Checkout my previous PowerWire articles on installing Open Source if you need help with that.
To assist in the development for this website we are going to use the Node Express framework.
Node Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications, and its very easy to use!
Use a PASE SSH shell session connected to your IBM i. Personally, I use Git Bash (which is installed as part of the Git for Windows package), but any shell will do (Please don’t use QShell/QP2Term! – Maybe an article on that in the future!)
The steps necessary for installing Node Express are as follows;
Point your browser at http://your_ibm_i:3000
And that is it, we now have a website up and running on our IBM i!
From the figure below, you can see that the express command has created lots of files and directories for us.
The directories are used as follows;
The app.js file is the main player here. It sets up the application and seamlessly joins all of the different parts together.
Let’s have a quick look at this file, and point out the bits we are interested in.
- The routes that have been setup for us. By default, we have the index and users route.
- Again routing. Works in association with step 1. If you want to setup new routes you would add them to these two steps.
- This step serves static assets from your public folder – If you want to use a different folder change it here
- This step specifies which view templating we are using. During the setup we stated PUG as the view template.
Every time we make a change to our code, we have to restart our node web server.
When we are continually making changes, and want to test those changes, this can be a right nuisance.
So how can we get around this?
One way is using a utility called Nodemon. Nodemon is a utility that will monitor for any changes in your source and automatically restart your server. Perfect for development!
Firstly, install Nodemon using NPM – Using the -g parameter will install it globally for all our applications on this box.
npm install -g nodemon
To start your application, in your shell, enter;
It will start your application and monitor for any changes. We have to use the -L parameter (L=Legacy) for it to recognise changes on our IFS.
If you want to manually restart your application at any time, just enter rs (Restart).
A great utility!
I’ll be using VS Code to make changes to this application. We can see the file structure in the figure below.
Before making any changes to this application, it’s a good time to start using source control. I would recommend running the command git init to start using Git for our source control.
If you like the font in the above figure, it has just been released by Microsoft, called Cascadia. It’s Open Source and can be found on GitHub at https://github.com/microsoft/cascadia-code
This font includes programming ligatures. These are where multiple characters appear to combine into a single character – great for programmers!
I find that a lot easier on my eyes – Don’t need to go to Specsavers so often!
Hopefully in this article I’ve shown how easy it is to use Node Express to quickly and easily create a website on your i.
We will further enhance it in my next article.
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
I’m looking forward to the next round of the IBM i 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.
Leave a Reply