Category Archives: Node.js on IBMi

Node.js on IBMi
Powerful technology update to enable RPG developers to leverage the latest in web technologies

Node.js Example application

Node.js on IBMil. The following sample code queries the DB2 database table QIWS.QCUSTCDT and returns the result set to the browser. Add the following code to a file called /home/sample.js.


var http = require('http');
var db = require('/QOpenSys/QIBM/ProdData/Node/os400/db2i/lib/db2');
http.createServer(function (req, res) {
     db.exec("SELECT LSTNAM, STATE FROM QIWS.QCUSTCDT", function(rs) {
                 res.writeHead(200, {'Content-Type': 'text/plain'});
}).listen(8081, 'IPaddress');
console.log('Server running at http://IPaddress:8081/');

From a terminal session (best to run ssh server in separate subsystem)

node /home/njs/sample.js

If no problem, you can browse the site to get the query result from database. The output of result set is in JSON format. You can use the JSON.stringify() function to convert it to a readable text, or access the key-value pairs directly.




1.      DB2 for i Access APIs


1.1.    Introduction

DB2i add-on for Node.js is a JavaScript API set for DB2 database manipulation on IBM i. The add-on is shipped with Node.js and located in /QOpenSys/QIBM/ProdData/Node/os400/db2i/. It contains a binary module db2i.node in thebin directory and a library file db2.js in the lib directory. If you want to copy the add-on to other places, please remain the folder structure.

To use the DB2i add-on, you only need to require the db2.js file in your source code.

1.2.    Examples

1.2.1. Basic Query

var db = require('/QOpenSys/QIBM/ProdData/Node/os400/db2i/lib/db2');
    db.debug(true);  // Enable Debug Mode if needed.
    db.init(function(){  // Initialize the environment for database connections.
           db.serverMode(true); // Enable Server Mode if needed
    db.conn(*LOCAL”, “USER”, “PASSWORD”, function(){ // Connect to a database
           db.autoCommit(true); // Enable the Auto Commit feature if needed.
    db.exec(“CREATE TABLE TEST.NAMEID (ID INTEGER, NAME VARCHAR(50), SALARY DECIMAL(8,2)));  // Create a new table in the database.
    db.exec(“INSERT INTO TEST.NAMEID VALUES (0, 'David', 999.99)); // Insert a new record in the table.
    console.log(“There are %d rows affected.”, db.numRows()); // Get the execution result.
    db.exec(“SELECT * FROM TEST.NAMEID,   // Query the data in the new table.
           function(jsonObj) {  // Print the output in a readble way.
           console.log(“Result: %s”, JSON.stringify(jsonObj));
           var fieldNum = db.numFields();
           console.log(“There are %d fields in each row.”, fieldNum);
           console.log(Name | Length | Type | Precise | Scale | Null);  // Print all the fields information.
           for(var i = 0; i < fieldNum; i++)
                  console.log(%s | %d | %d | %d | %d | %d”, db.fieldName(i), db.fieldWidth(i), db.fieldType(i), db.fieldPrecise(i), db.fieldScale(i), db.fieldNullable(i));
    db.exec(“DROP TABLE TEST.NAMEID);  // Delete the example table from the database.
    db.close();  // Release any used resource.
    } catch(e) {  // Exception handler

Node.js on IBMi | The power to modernise legacy applications

Node.js on IBMi

Node.js is an open source project based on Google Chrome V8 Engine. Node.js on IBMi provides a platform for server-side JavaScript applications running without browsers.

The event-driven, non-blocking I/O model makes it lightweight and very efficient. It also provides several built-in modules to simplify programming, especially for networking applications. Additionally, there are more third-party modules that can be easily installed with the built-in npm (Node Packaged Modules) tool.

The node.js engine allows you to run JavaScript code without the need for a browser.

The Node.js engine converts the JavaScript into machine code.

Node.js on IBMi

 Node.js on IBMi

Node.js is now being delivered and packaged for IBM i with the new IBM i product 5733-OPS – Open Source for IBM i – Option 1. This new offering includes the following:

  • Node.js runtime – Core Node.js runtime engine compiled to run in PASE on IBM i
  • DB2 for i access library  – Allows user to access content stored in DB2 for i.
  • Node.js toolkit for IBM i  – Allows user to access IBM i system resources, such as system status, system values, job information, message queue, object information, ILE Programs etc.
Note:  Node.js is a registered trademark of Joyent, Inc. in the United states and other countries. This module is not formally related to or endorsed by the official Joyent Node.js project.

Getting Started

To get going with Node.js on IBM i, use the following instructions

Software Prerequisites
How to obtain the new Open Source for IBM i Product – 5733OPS
Install & Setup Node.js on IBM i
Verifying the Node.js Environment
Running ‘Hello World’ in Node.js on IBM i
DB2 Access from Node.JS
Access IBM i Native Objects

API Reference

DB2 for i access APIs
Toolkit for IBM i APIs

Node.js Updates

It contains all the node.js PTF information.

Node.js updates

Additional References

XML Service
Node.js Community Site
IBM SDK for Node.js
Native JavaScript applications on IBM i with Node.js
Running Node.js with IBM HTTP Server for i

Source: IBM i Technology Updates : Node.js

RDI 9.5 Enhancements | IBM Systems Magazine

Fun Times for RDi Users With v 9.5

RDI 9.5 Enhancements, Version 9.5 of Rational Developer for i is now available. It does require a re-install—not just an update.  So what’s new in RDi V9.5?

RDI 9.5 Enhancements

The most significant new feature is the capability to format (or more accurately re-format) your free-form logic. What we’re talking about here is the matter of indentation of the code.Let’s say, for example, you have a FOR or DOx loop that has a SELECT/WHEN block nested inside it and an IF/ELSE block nested inside that. Now you need to add another level of nesting with another IF/ELSE block that falls between the FOR/DOx and the SELECT block.

One of the benefits of free-form logic is the capability to indent code to show the levels of nesting. This makes it easier for the next programmer coming along to follow the logic. Needless to say, this makes it critical that the indentation is accurate! Even if we make the bold assumption that the original code was indented properly to begin with (sadly in our experience, this is often not the case), introducing a new level in the middle requires shifting a bunch of code around to get the indentation to correctly reflect the nesting levels. There are various ways to do this manually, of course, but it was often not done properly or at best was time-consuming to do and tended to be somewhat error-prone. The new formatter only works on code that is already in free format—including file and data declarations, etc.

The built-in formatter for RDi V9.5 can be used on a specific block of code or, if no block is selected, the entire member is formatted.

The Crtl+Shift+F keyboard shortcut will invoke it or you can use menu options—either under the Source menu or via the right-click context menu under Source.You do have a few options on how the formatting is done. These are controlled via preferences on a new Formatter preference page under ILE RPG parser preferences.

There are options for how many spaces to indent and an option for whether or not you want WHEN/OTHER statements within a SELECT block indented. Take a look at the preference page to find a few others.



Source: IBM Systems Magazine – Fun Times for RDi Users With V9.5 Enhancements