
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
A Node.js module for Oracle Database access from JavaScript and TypeScript
The oracledb npm package is a Node.js driver for Oracle Database, providing a way to connect to Oracle databases, execute SQL queries, and manage database transactions. It supports various features such as connection pooling, data types, and advanced Oracle Database features.
Connecting to Oracle Database
This code demonstrates how to establish a connection to an Oracle Database using the oracledb package. It includes error handling and ensures the connection is closed after use.
const oracledb = require('oracledb');
async function run() {
let connection;
try {
connection = await oracledb.getConnection({
user: 'your_username',
password: 'your_password',
connectString: 'localhost/XEPDB1'
});
console.log('Connection was successful!');
} catch (err) {
console.error(err);
} finally {
if (connection) {
try {
await connection.close();
} catch (err) {
console.error(err);
}
}
}
}
run();
Executing SQL Queries
This code sample shows how to execute a SQL query using the oracledb package. It retrieves rows from the 'employees' table where the department_id is 101.
const oracledb = require('oracledb');
async function run() {
let connection;
try {
connection = await oracledb.getConnection({
user: 'your_username',
password: 'your_password',
connectString: 'localhost/XEPDB1'
});
const result = await connection.execute(
`SELECT * FROM employees WHERE department_id = :id`,
[101] // bind value for :id
);
console.log(result.rows);
} catch (err) {
console.error(err);
} finally {
if (connection) {
try {
await connection.close();
} catch (err) {
console.error(err);
}
}
}
}
run();
Using Connection Pooling
This code demonstrates how to use connection pooling with the oracledb package. It creates a pool of connections, retrieves a connection from the pool, executes a query, and then closes the connection and the pool.
const oracledb = require('oracledb');
async function run() {
let pool;
try {
pool = await oracledb.createPool({
user: 'your_username',
password: 'your_password',
connectString: 'localhost/XEPDB1',
poolMin: 2,
poolMax: 10,
poolIncrement: 1
});
const connection = await pool.getConnection();
const result = await connection.execute(`SELECT * FROM employees`);
console.log(result.rows);
await connection.close();
} catch (err) {
console.error(err);
} finally {
if (pool) {
try {
await pool.close(0);
} catch (err) {
console.error(err);
}
}
}
}
run();
The mysql package is a Node.js driver for MySQL databases. It provides similar functionalities to oracledb, such as connecting to the database, executing queries, and managing transactions. However, it is specifically designed for MySQL databases and does not support Oracle-specific features.
The pg package is a Node.js driver for PostgreSQL databases. Like oracledb, it allows you to connect to the database, execute SQL queries, and manage transactions. It is tailored for PostgreSQL and includes features specific to that database system, but it does not support Oracle Database features.
The mssql package is a Node.js driver for Microsoft SQL Server. It offers functionalities similar to oracledb, such as database connections, query execution, and transaction management. It is designed for use with SQL Server and includes features specific to that database, but it does not support Oracle Database features.
The node-oracledb add-on for Node.js powers high performance Oracle Database applications. Applications can be written in TypeScript, or directly in JavaScript.
Use node-oracledb 6.9.0 to connect Node.js 14.17, or later, to Oracle Database. Older versions of node-oracledb may work with older versions of Node.js.
Node-oracledb supports basic and advanced features of Oracle Database and Oracle Client. See the homepage for a list.
The node-oracledb module is open source and maintained by Oracle Corp. It is stable, well documented, and has a comprehensive test suite.
Run npm install oracledb
See Getting Started with Node-oracledb and Quick Start Node-oracledb Installation.
Node.js versions 14.17 and later.
Pre-built packages are available on npm and other mirror repositories.
Source code is also available.
Previous versions of node-oracledb supported older Node.js versions.
Oracle Client libraries are optional starting from node-oracledb 6.0. Older versions of node-oracledb require Oracle Client libraries.
Thin mode: By default node-oracledb (from version 6.0 onwards) runs in a 'Thin' mode which connects directly to Oracle Database.
Thick mode: Some advanced Oracle Database functionality is currently only available when optional Oracle Client libraries are loaded by node-oracledb. Libraries are available in the free Oracle Instant Client packages. Node-oracledb can use Oracle Client libraries 11.2 through 23ai.
Oracle Database
Thin mode: Oracle Database 12.1 (or later) is required.
Thick mode: Oracle Database 9.2 (or later) is required, depending on the Oracle Client library version. Oracle Database's standard client-server version interoperability allows connection to both older and newer databases. For example when node-oracledb uses Oracle Client 19c libraries, then it can connect to Oracle Database 11.2 or later.
See Documentation for the Oracle Database Node.js Add-on and the release notes.
See the examples directory. Start with examples/example.js.
Questions about node-oracledb can be posted on GitHub or Slack (link to join Slack).
To run the test suite, see test/README.
This project welcomes contributions from the community. Before submitting a pull request, please review our contribution guide.
Please consult the security guide for our responsible security vulnerability disclosure process.
Copyright (c) 2015, 2025, Oracle and/or its affiliates.
This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
If you elect to accept the software under the Apache License, Version 2.0, the following applies:
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FAQs
A Node.js module for Oracle Database access from JavaScript and TypeScript
The npm package oracledb receives a total of 209,110 weekly downloads. As such, oracledb popularity was classified as popular.
We found that oracledb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.