Continuing with my Node.js Express website on IBM i series, in this article I’ll show you how easy it is to add new records to our database.
In this article, we will develop some quick scripts to add these records.
It really is very simple in node.
As we know now, the first step to design our input screen. As an example, I’m just going to include a few input fields that relate to our employee table, so you get the gist.
This form is shown below.
The new pug file, called add.pug, in the /views directory.
This can be seen in the following figure.
Now we have our input screen, we need to add the node script for this new function.
We called this add.js in the /routes directory.
This new file can be seen below.
As we had to do with the previous articles in this series, we have to include the add function to our main driver app.js.
These additions are highlighted in the figure below.
Let us test if its all working.
Firstly, point your browser to the add page.
The testing is quite easily for this one, just check the records have been added to our employee table.
Press the Add Record button will call our POST section of the add.js script.
Looking good, but has it actually been added?
A quick Run SQL Scripts will tell us.
Yes, we now have Jimmy onboard!
As with all my previous articles on this topic, these changes have now been published to my GitHub repository, which can be found at this link. Hopefully, this will provide you with a template to experiment with Node.js on IBM i.
Hopefully in this article I’ve shown how easy it is to add new records to our employee database on our IBM i.
We will further enhance our application 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
Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems with over 40 years IBM midrange experience.
Leave a Reply