Lesson 6 · Node.js on IBM i — From RPG Developer to Modern IBM i Developer
Connect Node.js to Db2 for i
Use IBM's promise-based connector to establish a local Db2 for i connection and understand the job, authority, and naming context.
A Node.js application running on IBM i can connect directly to the local Db2 for i database without moving data to another platform.
In the previous lesson, you installed idb-pconnector.
This IBM project provides a promise-based interface over the native IBM i Db2 connector, which means we can use modern JavaScript async and await syntax.
The connection we are building
Node.js program in PASE
↓
idb-pconnector
↓
*LOCAL Db2
↓
Db2 for i
*LOCAL means the database on the IBM i where the Node.js process is running.
This is not a connection to a copied database. It is access to the same Db2 for i used by RPG and other IBM i applications.
Confirm the package
From the project directory:
cd "$HOME/eraofi-node"
npm list idb-pconnector
If it is not installed, run:
npm install idb-pconnector
The connector package installs only on IBM i, so install it in the project on the IBM i system.
Create a connection check
Create db-check.js:
const { Connection, Statement } = require('idb-pconnector');
async function main() {
const connection = new Connection({ url: '*LOCAL' });
const statement = new Statement(connection);
try {
const rows = await statement.exec('VALUES CURRENT_USER');
console.log(rows);
} finally {
await statement.close();
}
}
main().catch((error) => {
console.error('Db2 connection failed.');
console.error(error);
process.exitCode = 1;
});
Run it:
node db-check.js
The returned value should identify the database user for the connection. The exact shape of the displayed result can vary by connector version.
If the statement returns successfully, Node.js has executed SQL against the local Db2 for i database using the current IBM i security context. That successful round trip is all we are testing here.
Understand the JavaScript
This line loads two classes from the installed package:
const { Connection, Statement } = require('idb-pconnector');
This line describes a local database connection:
const connection = new Connection({ url: '*LOCAL' });
The statement object executes SQL through that connection:
const rows = await statement.exec('VALUES CURRENT_USER');
await pauses this function until the database operation completes. It does not freeze the entire Node.js runtime in the same way as a long synchronous operation.
The finally block closes the statement whether the operation succeeds or fails.
Authority still applies
The Node.js process does not gain unlimited database access.
The IBM i profile and connection context determine which schemas, tables, views, procedures, and services the application can use.
The existing security boundary still applies, just as it should.
In production, use a dedicated profile with only the authority the application requires. Do not solve an authority error by giving the application *ALLOBJ.
SQL naming and library lists
The example uses SQL naming and a special register, so it does not depend on a library list.
Real applications must make naming intentional. You can:
- qualify objects as
SCHEMA.TABLE - deliberately configure a library list when system naming is appropriate
- avoid assuming an interactive developer’s library list will exist in production
The connector also supports setting a library list, but qualified SQL names are often easier to reason about at the database boundary.
A support consideration
IBM’s repository describes idb-pconnector as production ready while also labeling it a technology preview.
Before standardizing on a connector, review its current status, supported Node.js versions, maintenance activity, and the support expectations of your organization. Other connection approaches, including ODBC, may be appropriate for different architectures.
Common connection failures
If the example fails, check:
- Was
idb-pconnectorinstalled on IBM i rather than copied from another platform? - Is the intended Node.js version active?
- Does the current profile have database access?
- Is the program running on the IBM i system where
*LOCALmakes sense? - Does the error identify a missing native prerequisite or incompatible package version?
Read the full error before changing authority or configuration.
Before the first query
Node.js can work with Db2 for i locally:
Connection({ url: '*LOCAL' })
+
Statement
+
await statement.exec(...)
In the next lesson, we will replace the connection check with a useful read-only query and work with the returned rows as JavaScript objects.
References
Documentation and references used for this lesson.

Comments
Share your thoughts, questions, or real-world IBM i experiences related to this article.