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

This post was updated on 20 March, 2019 to reflect changes in the way yum configuration works.

 

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 .

Configure Yum with Node.js and Oracle Instant Client Repositories

To set up your system to access Node.js and Oracle Instant Client repos on Oracle Linux yum server, install the oracle-nodejs-release-el7 and oracle-release-el7 RPMs. As of this writing, the Node.js 10 repo will be enabled by default when you install the Oracle Node.js repelase RPM

$ sudo yum -y oracle-node-release-el7 oracle-release-el7

Next, install Node.js 10 and the compatible node-oracledb, making sure to temporarily disable the EPEL repository to prevent the wrong version of Node.js getting installed.

$ sudo yum -y install --disablerepo=ol7_developer_EPEL 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 ( 5 )
  • Demetrio Tuesday, October 23, 2018
    Excelent!!!!
  • Andrew Friday, December 14, 2018
    Any recommendations to do this without having the database password sitting in a file on the server in clear text?
  • Sergio Friday, December 14, 2018
    @Andrew: See the node-oracledb documentation section on Exernal Authentication: http://oracle.github.io/node-oracledb/doc/api.html#extauth
  • Mika Monday, March 25, 2019
    Thanks!

    First command should be
    sudo yum -y install oracle-nodejs-release-el7 oracle-release-el7 ?
  • Sergio Monday, March 25, 2019
    @Mika - you are correct. Thanks for flagging!
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha