Informing the IBM Community

A NodeJS Website on IBM i – Adding Records

0
(0)

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.

This image has an empty alt attribute; its file name is Picture2.png

The new pug file, called add.pug, in the /views directory.

This can be seen in the following figure. 

This image has an empty alt attribute; its file name is Picture3.png
This image has an empty alt attribute; its file name is Picture-4.png

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.

This image has an empty alt attribute; its file name is Picture5-1024x879.png
This image has an empty alt attribute; its file name is Pic-6a.png

Main Driver

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.

This image has an empty alt attribute; its file name is Picture7-728x1024.png

Testing

Let us test if its all working. 

Firstly, point your browser to the add page.

https://your_ibmi/add


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.

This image has an empty alt attribute; its file name is Picture9.png

Looking good, but has it actually been added?

A quick Run SQL Scripts will tell us.

This image has an empty alt attribute; its file name is Picture10.png



Yes, we now have Jimmy onboard!

GitHub

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.

Conclusion

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.



How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.


Comments

Leave a Reply

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