App Configuration with OCI Centralized Configuration Providers in node-oracledb

Sharad Chandran
Oracle Developers
Published in
3 min readSep 2, 2024
Photo by Markus Winkler on Unsplash

Centralized Configuration Providers provide centralized storage and management of your database and application’s configuration information on Oracle Cloud Infrastructure (OCI).

Recently, I had published a detailed blog on Using OCI Centralized Configuration Providers for Oracle Database applications, which focuses on database configuration management.
We can also manage application-specific configuration on OCI. From node-oracledb 6.6 onwards, you can fetch properties specific to node-oracledb in Centralized Configuration Providers.

In this short blog, I will take you through the steps of creating a sample solution to fetch node-oracledb specific properties from Centralized Configuration Providers. I will use the Oracle Cloud setup that is detailed in my OCI Centralized Configuration Providers blog.

Create OCI Storage JSON File

{
"connect_descriptor": "localhost/orclpdb",
"user": "user1",
"password": "password1",
"node-oracledb": {
"poolMin": 2,
"poolMax": 5,
"poolIncrement": 2,
"poolTimeout": 39,
"poolPingInterval": 15,
"poolPingTimeout": 50,
"stmtCacheSize": 1000,
"prefetchRows": 10
}
}

Save this file (say oracledbConfig) in an OCI Bucket (say testBucket).

The node-oracledb specific properties are available as part of the node-oracledb sub-object. The connect_descriptor property for the database connect string is mandatory and should provided at a minimum.

Bucket page

Get the Object URL of this file.

Object URL

These steps are detailed in my OCI Centralized Configuration Providers blog.

Create and Run Node.js App

'use strict';
Error.stackTraceLimit = 50;
const oracledb = require('oracledb');

async function run() {
// Replace the connect string with correct OCI Config Store URL
// Replace xxxx in the connect string with the correct authentication parameter values
let pool, connection;
const options = {
// Replace the connect string here with URL of the 'oracledbConfig' file
// config-ociobject://<object_store_server_name>/n/{namespace}/b/{bucketname}/o/{filename}[/c/{network_service_name_or_alias}][?option1=value1&option2=value2...]
connectString: 'config-ociobject://objectstorage.region.oraclecloud.com/n/testNamespace/b/testBucket/o/oracledbConfig',
};
try {
// Create a pool and get a connection from the pool
pool = await oracledb.createPool(options);
console.log('Pool Created Successfully');

// List the pool parameters fetched from the OCI Config Store!
console.log('pool.stmtCacheSize:', pool.stmtCacheSize);
console.log('pool.poolMin:', pool.poolMin);
console.log('pool.poolMax', pool.poolMax);
console.log('pool.poolIncrement:', pool.poolIncrement);
console.log('pool.poolTimeout:', pool.poolTimeout);
console.log('pool.poolPingInterval:', pool.poolPingInterval);
console.log('pool.poolPingTimeout:', pool.poolPingTimeout);

// Create a connection from the pool
connection = await pool.getConnection();
console.log('\nCreated connection from the pool successfully!');

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

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

run();

This program creates an application-side connection pool with the pool parameters set from the OCI Centralized Configuration Providers.

This program gives the following output:

Pool Created Successfully
pool.stmtCacheSize: 1000
pool.poolMin: 2
pool.poolMax 5
pool.poolIncrement: 2
pool.poolTimeout: 39
pool.poolPingInterval: 15
pool.poolPingTimeout: 50

Created connection from the pool successfully!

As shown above, the application pool picks up all the node-oracledb parameters from the OCI Centralized Configuration Providers.

This provides the advantage of a standardized and centralized configuration setting for all the applications that use node-oracledb. The individual application developer does not need to worry about sizing the pool or cache of the application as the application.

Happy coding!

--

--

Sharad Chandran
Oracle Developers

Sharad Chandran is a Principal Product Manager at Oracle driving development of client interfaces & APIs for Oracle Database in C/C++, Python, Node.js, Go etc.