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 :
Installation of oracle java 7
Installation of Oracle 11g R2
Installation of Node.js
Use of node-oracle db plug-in to access oracleDB.
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-installerAfter installing java you need to set JAVA_HOME in bashrc, Do the following to set it:sudo gedit /etc/bash.bashrcAfter 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:$PATHLoad the changes by doing:source /etc/bash.bashrcNow check JAVA_HOMEecho $JAVA_HOMEIt should be like:/usr/lib/jvm/java-7-oracleHere you are done with the Installation of oracle java 7Now 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 unixodbcOnce you are done with that you have to download oracle 11G from :http://www.oracle.com/technetwork/products/express-edition/downloads/index.htmlAfter download do the following:unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip cd Disk1Now 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.rpmThe “/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/chkconfigThen 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 #EOFThen you need to give permission to the file by: sudo chmod 755 /sbin/chkconfigNow 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.confCopy 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=536870912Load the kernel parameters:sudo service procps startAfter 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/listenerNow run this command to install oracle 11G: sudo dpkg –install oracle-xe_11.2.0-2_amd64.debExecute 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/shmCreate the file “/etc/rc2.d/S01shm_load” sudo gedit /etc/rc2.d/S01shm_loadCopy 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 ;; esacSave the file and close.sudo chmod 755 /etc/rc2.d/S01shm_load
After successful installation of Oracle you need to configure it, to configure use the command below:sudo /etc/init.d/oracle-xe configureNow you have to set environment variable just to set everything properly.sudo gedit /etc/bash.bashrcPaste 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:$PATHNow reload bashrc:source /etc/bash.bashrcFinally start the service:sudo service oracle-xe startNow your are done with oracle !!!!After successfully installing & configuring Oracle ,let’s start with nodejs.
4.Installation of Node.js
Go tohttps://nodejs.org/download/and download linux binaries 64 bit.After downloading create node directory on home by: mkdir nodeAnd move node gz to node folder:mv ~/Downloads/node-v0.12.7-linux-x64.tar.gz ~/node cd ~/ nodeUnzip the file by: tar -zvf node-v0.12.7-linux-x64.tar.gzAfter 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:$PATHNow 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-oracledbUnzip file into “node-oracledb” folder at home directory.Now you have to change directory to “node-oracledb-master” directory: cd ~/node-oracledb/node-oracledb-masterBefore 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/publicAs you are in node-oracledb-master directory, now you have to run below command to install all dependencies:npm install -gNote : “-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_modulesHere you are done, Now you can run nodejs code with oracle.There are several example available. You can referhttps://github.com/oracle/node-oracledb/tree/master/examples .I hope you enjoy it. 🙂