X

News, tips, partners, and perspectives for the Oracle Linux operating system and upstream Linux kernel work

How to Install Node.js 10 with node-oracledb and Connect it to Oracle Database

A few months ago we added dedicated repositories for Node.js to the Oracle Linux yum server. These repos also include an RPM with the Oracle Database driver for Node.js, node-oracledb, so you can connect your Node.js application to the Oracle Database.

In this post I describe the steps to install Node.js 10 and node-oracledb Node.js to Oracle Database. If you are in a rush or want to try this out in a non-destructive way, I recommend you use the latest Oracle Linux 7 Vagrant box .

Grab the Latest Oracle Linux Yum Server Repo File

First, make sure you have the most recent Oracle Linux yum server repo file by grabbing it from the source:

$ sudo mv /etc/yum.repos.d/public-yum-ol7.repo /etc/yum.repos.d/public-yum-ol7.repo.bak
$ sudo wget -O /etc/yum.repos.d/public-yum-ol7.repo http://yum.oracle.com/public-yum-ol7.repo

Enable Node.js 10 Repo, Install Node.js and node-oracledb

$ sudo yum -y install yum-utils
$ sudo yum-config-manager --enable ol7_developer_nodejs10 ol7_oracle_instantclient
$ sudo yum -y install nodejs node-oracledb-node10

Connecting to Oracle Database

For my testing I used Oracle Database 18c Express Edition (XE). You can download it here. Quick Start instructions are here.

About Oracle Instant Client

node-oracledb depends on Oracle Instant Client. During OpenWorld 2018 we released Oracle Instant Client 18.3 RPMs on Oracle Linux yum server in the ol7_oracle_instantclient and ol6_oracle_instantclient repositories, making installation a breeze. Assuming you have enabled the repository for Oracle Instant Client appropriate for your Oracle Linux release, it will be installed as a dependency. As of release 3.0, node-oracledb is built with Oracle Client 18.3, which connects to Oracle Database 11.2 and greater. Older releases of Oracle Instant Client are available on OTN.

Add the Oracle Instant Client to the runtime link path.

$ sudo sh -c "echo /usr/lib/oracle/18.3/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf"
$ sudo ldconfig

A Quick Node.js Test Program Connecting to Oracle Database

I copied this file from the examples in the node-oracledb Github repo. Running this will tell us whether Node.js can connect to the database. Copy this code into a file called connect.js.

The file below comes from the same GitHub repo. Copy the code into a file called dbconfig.js and edit it to include your Database username, password and connect string.

Run connect.js with node

Before running connect.js, make sure NODE_PATH is set so that the node-oracledb module can be found.

$ export NODE_PATH=`npm root -g`
$ node connect.js
Connection was successful!

Join the discussion

Comments ( 1 )
  • Demetrio Tuesday, October 23, 2018
    Excelent!!!!
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services