node-oracledb: Connect Node program to Oracle Database Cloud Service in 30 minutes


If you want to execute sequel code against ORCL DB from Node your approach is node-oracledb. To get started follow setup instructions here.

Follow the steps I made to get it running in my new Mac here but documentation explains how to do it for a bunch of platforms.

NOTE: You need an oracle client, in my case I installed instant client. Steps are included in the mentioned doco.

Download the  zip or git clone this repo: [ https://github.com/oracle/node-oracledb.git ]

Ask for or grab your database connections details from the DBCS MyServices portal, then open examples directory with the latest trendy editor and edit dbconfig.js to point to your DBCS instance for example (settings are ficticious):

module.exports = {
 user : process.env.NODE_ORACLEDB_USER || "scott",
 password : process.env.NODE_ORACLEDB_PASSWORD || "tiger",
 connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING || "329.944.719.908/PDB1.contoso.oraclecloud.internal",
 externalAuth : process.env.NODE_ORACLEDB_EXTERNALAUTH ? true : false
};

Now you can test a couple of examples immediately:

MacBook-Pro-de-javier:examples javiermugueta$ node connect.js 

Connection was successful!

MacBook-Pro-de-javier:examples javiermugueta$ node select1.js 

[ { name: 'DEPARTMENT_ID' }, { name: 'DEPARTMENT_NAME' } ]

[ [ 180, 'Construction' ] ]

That’s all Folks!

Enjoy 😉

One comment

  1. […] steps here for node-oracledb setup except for the dbconfig.js file which must be set as […]

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

WordPress.com.
%d bloggers like this: