Integration of “Oracle 11G R2” with “Node.js” in Ubuntu

Emorphis - Oracle NodeJS

Node.js and oracle database are very powerful tool for the development of any dependent system, But to provide incorporation between these two is always a challenge. I would like to share the procedure that could help anybody who is suffering from incorporation and integration of both systems.
This piece of writing is going to cover :
  1. Installation of oracle java 7
  2. Installation of Oracle 11g R2
  3. Configure Oracle
  4. Installation of Node.js
  5. Use of node-oracle db plug-in to access oracleDB.
Let start!!!

1.Installation of oracle java 7

let’s start with oracle java installation of machine.
                        sudo add-apt-repository ppa:webupd8team/java
                        sudo apt-get update
                        sudo apt-get install oracle-java7-installer
After installing java you need to set JAVA_HOME in bashrc, Do the following to set it:
                       sudo gedit /etc/bash.bashrc
After opening this file add below lines after the last line of bashrc:
                      export JAVA_HOME=/usr/lib/jvm/java-7-oracle
                      export PATH=$JAVA_HOME/bin:$PATH
Load the changes by doing:
                     source /etc/bash.bashrc
Now check JAVA_HOME
                    echo $JAVA_HOME
It should be like:
                  /usr/lib/jvm/java-7-oracle
Here you are done with the Installation of oracle java 7
Now we’ll go for the installation of Oracle 11g 

2.Installation of Oracle 11g

Before starting the installation process there are some additional packages which are needed  to be install, They can be installed by :
                        sudo apt-get install alien libaio1 unixodbc
Once you are done with that you have to download oracle 11G from :
                       http://www.oracle.com/technetwork/products/express-edition/downloads/index.html
After download do the following:
                     unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip
                     cd Disk1
Now we have to convert “rpm” to “deb”, For that use the command below:
                     sudo alien –scripts -d oracle-xe-11.2.0-1.0.x86_64.rpm
The “/sbin/chkconfig file” is always needed by Red Hat package, which is not used in Ubuntu.
To successfully install Oracle XE we use a simple trick. 
First you need to create this file “/sbin/chkconfig” by using:
                     sudo gedit /sbin/chkconfig
Then you need to put below code in “chkconfig file”:
                   #!/bin/bash
                  # Oracle 11gR2 XE installer chkconfig hack for Ubuntu
                      file=/etc/init.d/oracle-xe
                      if [[ ! `tail -n1 $file | grep INIT` ]]; then
                      echo >> $file
                      echo ‘### BEGIN INIT INFO’ >> $file
                      echo ‘# Provides: OracleXE’ >> $file
                      echo ‘# Required-Start: $remote_fs $syslog’ >> $file
                      echo ‘# Required-Stop: $remote_fs $syslog’ >> $file
                      echo ‘# Default-Start: 2 3 4 5’ >> $file
                      echo ‘# Default-Stop: 0 1 6’ >> $file
                      echo ‘# Short-Description: Oracle 11g Express Edition’ >> $file
                      echo ‘### END INIT INFO’ >> $file
                       fi
                      update-rc.d oracle-xe defaults 80 01
                      #EOF
Then you need to give permission to the file by:
                       sudo chmod 755 /sbin/chkconfig
Now you have to set the additional kernel parameters, So create the file
                   /etc/sysctl.d/60-oracle.conf by :
                   sudo gedit /etc/sysctl.d/60-oracle.conf
Copy and paste the following into the file.“Kernel.shmmax” is the maximum possible value of physical RAM in bytes. 536870912 / 1024 /1024 = 512 MB.
                   # Oracle 11g XE kernel parameters
                       fs.file-max=6815744
                      net.ipv4.ip_local_port_range=9000 65000
                      kernel.sem=250 32000 100 128
                      kernel.shmmax=536870912
Load the kernel parameters:
                      sudo service procps start
After this, execute the following statements to make further changes required:
                     sudo ln -s /usr/bin/awk /bin/awk
                     mkdir /var/lock/subsys
                     touch /var/lock/subsys/listener
Now run this command to install oracle 11G:
                     sudo dpkg –install oracle-xe_11.2.0-2_amd64.deb
Execute the following to avoid getting ORA-00845: MEMORY_TARGET error.
 Note: replace “size=4096m” with the size of your (virtual) machine’s RAM in Mbs.
                    sudo rm -rf /dev/shm
                    sudo mkdir /dev/shm
                    sudo mount -t tmpfs shmfs -o size=4096m /dev/shm
Create the file “/etc/rc2.d/S01shm_load”
                    sudo gedit /etc/rc2.d/S01shm_load
Copy and paste the following in the file.
Note: replace “size=4096m” with the size of your machine’s RAM in Mbs.
                      #!/bin/sh
                     case “$1” in
                     start) mkdir /var/lock/subsys 2>/dev/null
                     touch /var/lock/subsys/listener
                     rm /dev/shm 2>/dev/null
                     mkdir /dev/shm 2>/dev/null
                     mount -t tmpfs shmfs -o size=4096m /dev/shm ;;
                     *) echo error
                     exit 1 ;;
                    esac
Save the file and close.
                    sudo chmod 755 /etc/rc2.d/S01shm_load

3.Configuring oracle

After successful installation of Oracle you need to configure it, to configure use the command below:
                  sudo /etc/init.d/oracle-xe configure
Now you have to set environment variable just to set everything properly.
                  sudo gedit /etc/bash.bashrc
Paste below code at the end of “bashrc file”:
                   export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
                   export ORACLE_SID=XE
                   export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`
                   export ORACLE_BASE=/u01/app/oracle
                   export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
                   export PATH=$ORACLE_HOME/bin:$PATH
Now reload bashrc:
                   source /etc/bash.bashrc
Finally start the service:
                  sudo service oracle-xe start
Now your are done with oracle !!!!
After successfully installing & configuring Oracle ,let’s start with nodejs. 

4.Installation of Node.js

Go to
                                https://nodejs.org/download/
and download linux binaries 64 bit.
After downloading create node directory on home by:
                                 mkdir node
And move  node gz to node folder:
                                 mv ~/Downloads/node-v0.12.7-linux-x64.tar.gz   ~/node
                                 cd ~/ node
Unzip the file by:
                                tar -zvf node-v0.12.7-linux-x64.tar.gz
After that you need to set node path to “bashrc” to access it globally, to do this use below command:
                               sudo gedit /etc/bash.bashrc
                              export PATH=/home/amit/node/node-v0.12.7-linux-x64/bin:$PATH
Now try to access node command from terminal, it should work.
                              node -v 

5.Use of node-oracledb plugin to access oracleDB

First of all you need to download node oracle driver from below URL:
                                 https://github.com/oracle/node-oracledb
Unzip file into “node-oracledb” folder at home directory.
Now you have to change directory to “node-oracledb-master” directory:
                                 cd ~/node-oracledb/node-oracledb-master
Before installing the driver you need to set below parameter into “bashrc” :
                                 export OCI_LIB_DIR=$ORACLE_HOME/lib
                                 export OCI_INC_DIR=$ORACLE_HOME/rdbms/public
As you are in node-oracledb-master directory, now you have to run below command to install all dependencies:
                                 npm install -g
Note : “-g” is for set it globally.
Now NODE_PATH and LD_LIBRARY_PATH should be exported to “bashrc”.
                                export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
                                export NODE_PATH=/home/amit/node/node-v0.12.7-linux-x64/lib/node_modules
Here you are done, Now you can run nodejs code with oracle.
There are several example available. You can refer
                                https://github.com/oracle/node-oracledb/tree/master/examples .
I hope you enjoy it. 🙂

SHARE