Usher in a new era with the node-oracledb 6.0 pure JavaScript thin driver!

Sharad Chandran
Oracle Developers
Published in
5 min readMay 24, 2023
Launch
Photo by Iván Díaz on Unsplash

Release announcement: A new major release of node-oracledb, the Node.js and TypeScript module for accessing Oracle Database, is available from npm.

Top feature: Thin Mode

This version of node-oracledb is now a ‘Thin’ mode driver by default. The Thin mode is implemented purely in JavaScript and connects directly to Oracle Database. This mode eliminates the need to download Oracle client libraries to connect to Oracle Database.

Thin mode can be used on any platform that supports JavaScript. It takes up smaller install footprint compared to the previous version, provides better performance atomics, and the simpler deployment benefit of a pure JavaScript driver.

Thin mode has all the features you want. For example, it lets you connect to Oracle cloud and on-premises databases, supports connection pooling, provides extensive SQL and PL/SQL support, JSON duality view support, handles standard datatypes including JSON and LOBs, and more. Check out the latest node-oracledb documentation for all the latest features.

You can also enable a ‘Thick’ mode that will allow the optional use of Oracle client libraries with some additional functionality. This mode will include all the features of the previous node-oracledb release, along with the other enhancements.

How easy is running a Node.js app with node-oracledb?

As easy as saying 123! Assuming you have Node.js installed and access to a running Oracle Database service.

Then install node-oracledb from the npm registry:

npm install oracledb

Now run the following sample Node.js program (with your database credentials set in the dbConfig object):

const oracledb = require('oracledb');

async function runApp() {

let connection;
let dbConfig = {
user : "user",
password : "password",
connectString : "localhost/orclpdb"
};

try {
// Get a standalone Oracle Database connection
connection = await oracledb.getConnection(dbConfig);
console.log('Connection was successful!');

// Run a simple SQL on the connection
const sql = `SELECT sysdate FROM dual`;
const result = await connection.execute(sql);
console.log(`The system date and time is:\n${result.rows[0][0]}`);

} catch (err) {
console.error(err);
} finally {
if (connection) {
try {
await connection.close();
} catch (err) {
console.error(err);
}
}
}
}

runApp();

You will see an output with the current date and time:

Connection was successful!
The system date and time is:
Tue Apr 25 2023 13:17:51 GMT+0530 (India Standard Time)

In essence, the Thin mode allows you to connect to Oracle Database in a flash! No other software or configuration is needed, Easy-peasy!

Ok, what makes Thin mode so cool, you ask!?

The node-oracledb Thin mode drastically reduces the disk space required. It takes up only 1 Megabyte as compared to 240 Megabytes when you install Instant Client libraries to use Thick mode. This will be useful for 3rd party packaging, apps running on networks with limited download speeds and optimizing runtime memory requirements.

Size comparison for Thin and Thick modes

The Thin mode lets you run node-oracledb apps on platforms like Alpine Linux, Apple M1/M2, some cloud deployments and IoT devices, where the setup of Oracle Client libraries is difficult, or setup is not available.

The Thin mode also executes SQL statements faster than node-oracledb 5.5 on average. We ran atomic tests on certain Insert and Select operations with node-oracledb on a Linux x86_64 machine with Oracle 19c Database (remote) and found the Thin mode to be 14% faster on average than node-oracledb 5.5. The performance profile will vary across different environments and for distinct user data.

Performance of node-oracledb 6.0 Thin mode vs. node-oracledb 5.5

However, there may be other factors in real-world scenarios (for example, multi-threading support), that may influence performance results for the Thin mode. As Thin mode is pure JavaScript, the internal worker threads aren’t needed. So, more work is done in the main Node.js thread with the Thin mode, which adds another variable to the performance profile.

Great, but what else does the new node-oracledb version offer me?

Node-oracledb 6.0 also introduces Fetch Type Handler support which allows you to specify your own converter function that you can use to modify the metadata that is fetched by your app. This feature allows for more flexibility and power when data is returned to the app. You can use it for formatting numbers and dates or change the case of column headings.

Support for Oracle Database 23c BOOLEAN datatype is also available in this version of node-oracledb.

Node-oracledb 6.0 supports Node.js 14.6 and higher versions. Thin Mode connects to Oracle Database 12.1 and onwards. Thick mode connects to Oracle Database 9.2 and later versions, depending on the Oracle client libraries available.

See the CHANGELOG for the complete list of changes in this release.

How do you upgrade to the latest node-oracledb version for your Node.js apps?

You can upgrade your existing node-oracledb add-on by updating your package.json requirements:

"dependencies": {
"oracledb": "^6.0"
},

To run your app in Thin mode, ensure that you remove any calls to initOracleClient(). If you want to enable Thick mode, add an initOracleClient() call to your app, before the first database API call is made. Check our extensive Thin mode vs. Thick mode blog for all the nitty-gritty details!

Resources

Since the Thin mode is completely written in JavaScript, it will be easier for JavaScript developers to contribute Pull Requests (PRs) to the node-oracledb source code in our GitHub repository. So, contributions to improving node-oracledb are more than welcome. Please see CONTRIBUTING.

On a final note — Fresh off the press!

Oracle 23c Database Free Release is now available!
Do check out Oracle Database 23c’s new and exciting features such as BOOLEAN datatype and JSON Relational Duality views. These features can be used with the latest node-oracledb releases.

--

--

Sharad Chandran
Oracle Developers

Sharad Chandran is a Principal Product Manager at Oracle working on building client-side interfaces & APIs for the Oracle DB in C/C++, Python, Node.js, Go etc.