StrongLoop Oracle Database Driver
raw JSON →The `strong-oracle` package is a Node.js driver for connecting to Oracle databases, leveraging Oracle's own Instant Client libraries. It allows Node.js applications to interact with Oracle databases by providing a thin wrapper around the Oracle Call Interface (OCI). As of version 1.9.0, it remains a CommonJS module. Its release cadence appears to be slow, with `1.x` being the primary stable branch, suggesting it is in maintenance mode rather than active feature development. A key differentiator is its reliance on a locally installed Oracle Instant Client, which requires careful manual setup of environment variables, symbolic links, and system libraries (like `libaio` on Linux) specific to the operating system and architecture. This direct OCI binding offers performance and features consistent with Oracle's native client, but introduces a significant pre-installation and configuration overhead compared to pure JavaScript drivers. The library supports various connection methods, including direct hostname/port, full TNS connection strings, and TNS aliases configured in `tnsnames.ora`.
Common errors
error Error: NJS-045: cannot load the Oracle Instant Client libraries ↓
OCI_HOME, OCI_LIB_DIR, OCI_INCLUDE_DIR environment variables are set. On Linux, ensure LD_LIBRARY_PATH (or /etc/ld.so.conf.d/) is configured. On MacOS, check DYLD_LIBRARY_PATH. On Windows, confirm Path includes the Instant Client directories (with correct order). error ORA-12154: TNS:could not resolve the connect identifier specified ↓
database name, ensure it's a valid service name or SID. If using tns, verify the tnsnames.ora file is correctly configured, TNS_ADMIN environment variable points to its directory, and the alias exists and is spelled correctly. Try a full connection string directly in connectData.tns. error Error: Missing libaio.so.1 ↓
libaio: sudo apt-get install libaio1 (Debian/Ubuntu) or sudo yum install libaio (Fedora/CentOS/RHEL). error The specified module could not be found. (Windows, during `require('strong-oracle')`) ↓
Path environment variable, specifically the order of instantclient\vcXX and instantclient entries as described in the warnings. Warnings
breaking Mismatch in system architecture (32-bit vs. 64-bit) between Node.js, your operating system, and the downloaded Oracle Instant Client packages will prevent `strong-oracle` from loading its native bindings, leading to runtime errors. ↓
gotcha Oracle Instant Client and `libaio` (on Linux) are mandatory external dependencies that must be manually installed and configured. Incorrect setup of environment variables (`OCI_HOME`, `OCI_LIB_DIR`, `OCI_INCLUDE_DIR`, `LD_LIBRARY_PATH`/`DYLD_LIBRARY_PATH`/`Path`) or missing symbolic links can cause 'module not found' or OCI initialization errors. ↓
gotcha On Windows, the order of directories in the `Path` environment variable is critical. The `vc11` or `vc10` subdirectory of `instantclient` must appear *before* the main `instantclient` directory to ensure the correct Visual Studio runtime libraries are loaded. ↓
gotcha The `strong-oracle` driver defaults to OCI v12 (v11 on Mac OS X). If your Oracle Instant Client version differs and causes compatibility issues, you may need to explicitly set the `oci_version` via `GYP_DEFINES`. ↓
Install
npm install strong-oracle yarn add strong-oracle pnpm add strong-oracle Imports
- strong-oracle module wrong
import oracle from 'strong-oracle';correctconst oracle = require('strong-oracle'); - oracle factory function wrong
const { connect } = require('strong-oracle');correctconst oracle = require('strong-oracle')(settings);
Quickstart
const oracle = require('strong-oracle')({});
const connectData = {
hostname: 'localhost',
port: 1521, // Default Oracle Listener port
user: 'test',
password: process.env.ORACLE_PASSWORD ?? 'test',
database: 'ORCL' // Service name or SID
};
oracle.connect(connectData, function(err, connection) {
if (err) {
console.error('Failed to connect to Oracle:', err);
return;
}
console.log('Successfully connected to Oracle database!');
// Example: Execute a simple query
connection.execute('SELECT SYSDATE FROM DUAL', [], function(queryErr, result) {
if (queryErr) {
console.error('Error executing query:', queryErr);
} else {
console.log('Current database date:', result.rows[0].SYSDATE);
}
// Always close the connection when done
connection.close(function(closeErr) {
if (closeErr) {
console.error('Error closing connection:', closeErr);
} else {
console.log('Connection closed.');
}
});
});
});