Lift to Cloud – Nodejs oracledb application to OCI

Our journey to cloud – We had NodeJS apps running on windows servers connecting to the enterprise database. We moved them to an OCI hosted windows server and ATP database. Here is a rundown of how to do that move.

Requirements

  • A wallet from your ATP DB (Available from OCI Console)
  • Remote Desktop access to your Windows Server Instance on OCI
  • GitHub access
  • Visual Studio Code (or your editor of choice)

Initial Steps

  1. Create GitHub Repo for the application
  2. Install GitHub from Git – Downloading Package (git-scm.com)
  3. Install Nodejs from Node.js — Download Node.js® (nodejs.org)
  4. Clone the application into a folder on your target OCI Instance [easy with vscode: command palette git clone paste clone URL]
  5. Run a terminal in the folder you cloned you app to
  6. Run ‘npm install’ to get the libraries you have used – we are paying careful attention to the ‘oracledb’ package, as this is the main topic of this blog.

At this point we could run the application – but it would not connect with the database. We will be aiming to install the Oracle Instant client and run the application connection in thick mode.

Installation of Instant Client

https://node-oracledb.readthedocs.io/en/latest/user_guide/installation.html#clientwin

Go ahead and install the latest Client – we used 21-13 Basic.

Instant Client for Microsoft Windows (x64) 64-bit (oracle.com)

You will need an Oracle account to log into that download area, but you can set it up for free, just for the license agreement I suppose.

I should mention that there are advantages to running in thick mode (aside from the obvious advantage that it actually works it is very simple to connect with as we will see. You have to use thick mode if you want to work with blobs we have found.

As it says above, you will need the Microsoft redistributable to be installed – which is a crucial step. For 21-11 we used 2019.

Latest supported Visual C++ Redistributable downloads | Microsoft Learn

Note: When you install Node.js you can opt for the recommended additional workloads and chocolatey (the installer) will also automatically install python and MS Redistributable.

Configure the Connection

Set ORACLE_HOME, PATH environment variables:

From a powershell terminal in VSCODE or from windows system properties tool:

setx ORACLE_HOME "C:\S250\instantclient_21_13"
setx Path "$env:Path;C:\S250\instantclient_21_13"

WALLET placement

unzip and copy the ATP wallet contents/files into your instant client network/admin folder:

Key Point

So the tnsnames.ora file is placed in the network/admin folder

setx TNS_ADMIN "C:\S250\instantclient_21_13\network\admin"

Open up your tnsnames.ora file and make a note of the connection you would like to use.

With that done, your Instant client will pick up the wallet with this simple configuration: Note we picked s250development_high:

const oracledb = require('oracledb');

oracledb.initOracleClient();

async function run() {
    connection = await oracledb.getConnection({
        user: "admin",
        password: "yours",
        connectString: "s250development_high"
    });

    const result = await connection.execute(`SELECT * FROM DUAL`);
    console.log("Result is:", result.rows);

    await connection.close();   // Always close connections
}
PS C:\Users\opc\Projects\ADBCon> node index.js
Result is: [ [ 'X' ] ]

All done.

Bye from us at solution250, until the next blog


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *