node-ibm_db
An asynchronous/synchronous interface for node.js to IBM DB2 and IBM Informix.
Async APIs return promises if callback function is not used. Async APIs supports async-await programming style.
-
Supported Platforms - Windows64, MacOS64, MacARM64, Linuxx64, AIX64, Linux on IBM Z, Linux on Power PC and z/OS.
-
MacOS with Silicon Chip - Supported from ibm_db@3.3.0 onwards using v12.x clidriver.
-
MacOS with Intel Chip - Supported using v11.x clidriver only. By default v11.5.9 clidriver will get downloaded.
-
ibm_db v3.2.5 is the last version to use clidriver of version 11.5.9 by default. ibm_db@3.3.0 onwards v12.1.x clidriver get autodownloaded by default and hence v12.1 db2connect license is required. However, user can use older db2connect license when ibm_db get installed using npm install ibm_db -clidriver="v11.5.9" command.
-
SQL1598N Error - It is expected in absence of valid db2connect license. Please click here and read instructions.
-
GSKit Error - Check instructions as documented here.
API Documentation
-
For complete list of ibm_db APIs and example, please check APIDocumentation.md
-
For Secure Database connection using SSL/TSL: Check here.
-
Got an issue? Need Help? : Check common issues and suggestion here.
Prerequisite
ibm_db installs precompiled binaries for Windows x64, Linux x64, macOS (Intel and Apple Silicon), AIX, and Linux on IBM Z (s390x). No compiler or build tools are normally required on these platforms. During npm install, ibm_db also downloads and installs the matching IBM Db2 ODBC/CLI driver, so no separate Db2 client install is needed.
- Node.js: any version works (v4.0.0+ uses NAPI, which is binary-compatible across Node.js/Electron versions). Latest version tested: 26.13.0.
- Linux: just needs the standard C/C++ runtime libraries that ship with most distros (
libstdc++, libc, libgcc, libz). On UBI9-based images, also install libcrypt and libxcrypt-compat (libcrypt was dropped from the base image).
- Alpine Linux is not supported (musl libc, no precompiled binary available).
- Windows / macOS: nothing extra needed beyond Node.js itself.
Just run npm install ibm_db as shown below. AIX and Linux on IBM Z obtain their precompiled binary from GitHub, so installation on those systems requires access to the binary download.
Native compilation is only required on platforms without an available precompiled binary (such as Linux on Power and z/OS), or if you explicitly want to build from source. AIX and Linux on IBM Z (s390x) use downloaded precompiled binaries and do not normally require a compiler.
- A C++ compiler supporting C++11 is required (gcc >= 8.4 on non-Windows; Node.js v24+ requires C++20, so install
llvm on macOS).
python3 (>= 3.8, required by node-gyp), make/GNU make, and node must be on PATH.
- Windows source builds: use Visual Studio 2022 or newer with the C++ build tools installed, from a Visual Studio Developer Command Prompt. VC++ 2015.3 (v140) is a legacy option only for Node.js/node-gyp versions compatible with that toolset. This is not needed for the normal Windows x64 install, which uses a precompiled binary.
- macOS: install Xcode from the App Store.
- Docker/containers: install
make gcc g++(gcc-c++) python3 node; for root, use npm install --unsafe-perm ibm_db. If you hit a libcrypt error, also install libxcrypt-compat, e.g.:
RUN apt-get update && apt-get install gcc g++ libcrypt libxcrypt-compat python3 make -y
- WSL: install the
build-essential package first.
- z/OS: ODBC support is part of IBM Db2 for z/OS >= 11.0; follow the setup here. Tested with node-gyp 3.4.0 / npm 3.10.10 / ibm_db 2.8.1 on z/OS v2.4, Db2 v12.0.
On platforms with a precompiled binary, ibm_db falls back to that binary if native compilation fails. For AIX and Linux on IBM Z, the installer downloads the binary directly.
Install
You may install the package using npm install command:
npm install ibm_db
You may install ibm_db in quiet mode using either of below commands:
npm install --quiet ibm_db
npm install -q ibm_db
You may install ibm_db in silent mode using either of below commands:
npm install --silent ibm_db
npm install -s ibm_db
When using ibm_db in a package.json file, you can set below environment variables to install ibm_db in --quiet or --silent mode:
export npm_config_loglevel=warn => For quiet mode installation.
export npm_config_loglevel=silent => For silent mode installation.
To install using specific version of clidriver from https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/:
npm install ibm_db -clidriver=<version>
npm install ibm_db -clidriver=v11.1.4
npm install ibm_db -clidriver=v11.5.6
You can also set system level environment variable CLIDRIVER_DOWNLOAD_VERSION to instruct ibm_db to download that version of clidriver.
export CLIDRIVER_DOWNLOAD_VERSION=v11.5.9
npm install ibm_db
You can set the version of "clidriver", IBM_DB_DOWNLOAD_URL or "cafile" in config section of your package.json file.
In that case, no need to pass these options with npm install command or no need to set in .npmrc to avoid warning message with npm v11.x
package.json:
{
"name": "foo",
"config": {
"clidriver": "v11.5.9"
}
}
For Docker Linux Container (building from source), use below commands:
yum install make gcc gcc-c++ kernel-devel openssl-devel bzip2-devel
install python3.x
install node.js
npm install --unsafe-perm ibm_db
Alpine Linux is not supported by ibm_db as it is an arm64 architecture.
-
npm install ibm_db internally downloads and install platform specific clidriver of recent release from here.
To avoid this download, you can manually download clidriver from this location or install any verison of IBM Data Server Driver Package or Db2 Client or Sever in your system and point the install directory using IBM_DB_HOME environment variable. If IBM_DB_HOME or IBM_DB_INSTALLER_URL is set, npm install ibm_db do not download clidriver.
-
ibm_db works with all supported versions of Db2 Client and Server. Instead of using open source driver specific clidriver for ibm_db, you may download and install DSDRIVER or DB2Client from IBM Fix Central or IBM Passport Advantage of Db2 V11.1.0.0 onwards.
-
If IBM_DB_HOME or IBM_DB_INSTALLER_URL is not set, ibm_db always downloads open source driver specific clidriver and use it. Ignores any other installation.
For more installation details please refer: INSTALLATION GUIDE
If installation fails while downloading clidriver, follow instructions as documented here.
Validate your installation
- Update database connection info in
node_modules\ibm_db\test\config.json file.
- Run
node node_modules\ibm_db\test\test-basic-test.js command.
Important Environment Variables and Download Essentials
IBM_DB_HOME :
-
USE:
- On distributed platforms, set this environment variable if you want to avoid downloading of clidriver from the IBM Hosted URL or from the internet.
- On z/OS, set this environment variable to the High Level Qualifier (HLQ) of your Db2 datasets. During
npm install, the module will automatically reference ODBC driver header files under: $IBM_DB_HOME.SDSNC.H and the sidedeck definitions in $IBM_DB_HOME.SDSNMACS(DSNAO64C) to build the node binding.
-
HOW:
- On distributed platforms, set IBM_DB_HOME environment variable to a pre-installed db2 client or server installation directory.
- On z/OS, set IBM_DB_HOME environment variable to the High Level Qualifier (HLQ) of your Db2 datasets. For example, if your Db2 datasets are located as
DSNC10.SDSNC.H and DSNC10.SDSNMACS, you need to set IBM_DB_HOME environment variable to DSNC10 with the following statement (can be saved in ~/.profile):
IBM_DB_INSTALLER_URL :
-
USE:
- Set this environment variable to by-pass the IBM Hosted URL for downloading odbc/clidriver.
-
HOW:
- Set IBM_DB_INSTALLER_URL environment variable with alternate odbc/clidriver downloading URL link or with locally downloaded "tar/zipped clidriver's parent directory path.
-
TIP:
- If you don't have alternate hosting URL then, you can download the tar/zipped file of clidriver from the IBM Hosted URL and can set the IBM_DB_INSTALLER_URL environment variable to the downloaded "tar/zipped clidriver's" parent directory path. No need to untar/unzip the clidriver and do not change the name of downloaded file.
DOWNLOAD_CLIDRIVER :
-
USE:
- Set this environment variable to force downloading of odbc/clidriver. If clidriver is already present, existing clidriver will get deleted. If IBM_DB_HOME environment variable is set, still clidriver will get downloaded by ignoring value of IBM_DB_HOME.
-
HOW:
- On distributed platforms, Set DOWNLOAD_CLIDRIVER environment variable to
true to force downloading of clidriver from IBM hosted URL. Never set DOWNLOAD_CLIDRIVER on z/OS system.
CLIDRIVER_DOWNLOAD_VERSION :
-
USE:
- Set this environment variable for downloading of specific version of odbc/clidriver at install time if clidriver do not exist under
ibm_db/installer directory or not pointed by environment variable IBM_DB_HOME. If clidriver is already present, existing clidriver will not get deleted unless DOWNLOAD_CLIDIVER is set.
-
HOW:
- On distributed platforms, Set DOWNLOAD_CLIDRIVER environment variable to
true and set environment variable CLIDRIVER_DOWNLOAD_VERSION to force downloading of clidriver from IBM hosted URL. Never set CLIDRIVER_DOWNLOAD_VERSION on z/OS system.
Download clidriver (based on your platform & architecture) from the below IBM Hosted URL:
DOWNLOAD CLI DRIVER
Cli Drivers for Specific Platform and Architecture
| Platform |
Architecture |
Cli Driver |
Supported |
| AIX |
ppc |
aix32_odbc_cli.tar.gz |
Yes |
|
others |
aix64_odbc_cli.tar.gz |
Yes |
| Darwin |
x64 |
macos64_odbc_cli.tar.gz |
Till v11.5.9 |
| Darwin |
arm64 |
macarm64_odbc_cli.tar.gz |
From v12.1.0 |
| Linux |
x64 |
linuxx64_odbc_cli.tar.gz |
Yes |
|
s390x |
s390x64_odbc_cli.tar.gz |
Yes |
|
s390 |
s390_odbc_cli.tar.gz |
Yes |
|
ppc64 (LE) |
ppc64le_odbc_cli.tar.gz |
Yes |
|
ppc64 |
ppc64_odbc_cli.tar.gz |
Yes |
|
ppc32 |
ppc32_odbc_cli.tar.gz |
Yes |
|
others |
linuxia32_odbc_cli.tar.gz |
Yes |
| Windows |
x64 |
ntx64_odbc_cli.zip |
Yes |
|
x32 |
nt32_odbc_cli.zip |
Not supported with node-ibm_db |
| z/OS |
s390x |
ODBC support from IBM Db2 for z/OS 11.0 or 12.0 |
Yes |
Configure ODBC driver on z/OS
Please refer to the ODBC Guide and References cookbook for how to configure your ODBC driver. Specifically, you need to:
-
Apply Db2 on z/OS PTF UI60551 to pick up new ODBC functionality to support Node.js applications.
-
Bind the ODBC packages. A sample JCL is provided in the SDSNSAMP dataset in member DSNTIJCL. Customize the JCL with specifics to your system.
-
Ensure users that should be authorized have authority to execute the DSNACLI plan. Included are samples granting authority to public (all users), or specific groups via SQL GRANT statements, or alternately via RACF. The security administrator can use these samples as a model and customize/translate to your installation security standards as appropriate.
Examples using SQL GRANT statement:
Example 1: Grant the privilege to execute plan DSNACLI to RACF group, DBCLIGRP.
GRANT EXECUTE ON PLAN DSNACLI TO DBCLIGRP;
Example 2: Grant the privilege to execute plan DSNACLI to all users at the current server.
GRANT EXECUTE ON PLAN DSNACLI TO PUBLIC;
Examples using Access Control Authorization Exit for Db2 authorization:
Define profile for plan DSNACLI execute privilege check
RDEFINE MDSNPN DB2A.DSNACLI.EXECUTE UACC(NONE) OWNER(DB2OWNER)
Example 1: PERMIT the privilege to execute plan DSNACLI to RACF group, DBCLIGRP
PERMIT DB2A.DSNACLI.EXECUTE ID(DBCLIGRP) ACCESS(READ) CLASS(MDSNPN)
Example 2: PERMIT the privilege to execute plan DSNACLI to all users at the current server
PERMIT DB2A.DSNACLI.EXECUTE ID(*) ACCESS(READ) CLASS(MDSNPN)
Issue SETROPTS command to refresh in-storage profile lists
SETR RACLIST(MDSNPN) REFRESH
-
Update the STEPLIB environment variable to include the Db2 SDSNEXIT, SDSNLOAD and SDSNLOD2 data sets. You can set the STEPLIBenvironment variable in your .profile with the following statement, after defining IBM_DB_HOME to the high level qualifier of your Db2 datasets as instructed above:
# Assumes IBM_DB_HOME specifies the HLQ of the Db2 datasets.
export STEPLIB=$STEPLIB:$IBM_DB_HOME.SDSNEXIT:$IBM_DB_HOME.SDSNLOAD:$IBM_DB_HOME.SDSNLOD2
-
Configure an appropriate Db2 ODBC initialization file that can be read at application time. You can specify the file by using either a DSNAOINI data definition statement or by defining a DSNAOINI z/OS UNIX environment variable. For compatibility with ibm_db, the following properties must be set:
In COMMON section:
MULTICONTEXT=2
CURRENTAPPENSCH=ASCII
FLOAT=IEEE
In SUBSYSTEM section:
MVSATTACHTYPE=RRSAF
Here is a sample of a complete initialization file:
; This is a comment line...
; Example COMMON stanza
[COMMON]
MVSDEFAULTSSID=VC1A
CONNECTTYPE=1
MULTICONTEXT=2
CURRENTAPPENSCH=ASCII
FLOAT=IEEE
; Example SUBSYSTEM stanza for VC1A subsystem
[VC1A]
MVSATTACHTYPE=RRSAF
PLANNAME=DSNACLI
; Example DATA SOURCE stanza for STLEC1 data source
[STLEC1]
AUTOCOMMIT=1
CURSORHOLD=1
-
Please make sure tagging of your odbc.ini file is "binary" or "mixed":
chtag -b $DSNAOINI
or
chtag -m -c IBM-1047 $DSNAOINI
If file is tagged text (chtag -t -c IBM1047 $DSNAOINI) the S0C4 abend occurs.
Reference Chapter 3 in the ODBC Guide and References for more instructions.
How to get ibm_db instance?
The simple api is based on the instances of Database class. You may get an
instance by one of the following ways: