Lab 4: Configuring node.js apps with ATP Autonomous Transaction Processing provides all of the performance of the market-leading Oracle Database in an environment that is tuned and optimized for transaction processing workloads. Oracle Autonomous Transaction Processing (or ATP) service provisions in a few minutes and requires very little manual ongoing administration. ATP provides a TLS 1.2 encrypted secure connectivity for applications. In fact, using a secure encryption wallet is the only way to connect to an ATP service instance, ensuring every connection to your database is secure, regardless how it gets routed. Lab Objective Build a linux node.js application server and connect it to an Oracle ATP database service Steps Provision a linux compute VM to serve as the app server Install node.js, python 2.7 and required libaio libraries Install and configure oracle instant client Install node oracle drivers through npm Upload connection wallet and run sample app Let s get started. Provision a linux compute VM to serve as the app server
Log into your Oracle Cloud Infrastructure compute console and provision a Oracle Linux, Ubuntu or a CentOS machine. Note that you would need to provision an virtual cloud network (VCN) in your compartment. Note the public IP address of the machine provisioned. Now lets ssh into this host and configure it to run node.js on ATP Install node.js, python 2.7 and required libaio libraries ssh as user opc to your host machine $ ssh i /Users/kbhanushali/priv-ssh-key opc@ipaddress Download and install node.js, python and git. We will need git to download instant client and sample app. $ curl --silent --location https://rpm.nodesource.com/setup_10.x sudo bash - $ sudo yum install nodejs Install python 2.7 if it does not already exist on your machine. OEL 7.5 comes preinstalled with python 2.7
Ensure libaio is installed and up to date $ sudo yum install libaio You can check your node, npm and python installs using $ node --version $ npm --version $python --version Install and configure oracle instant client Next, lets download and install the oracle instant client software. You can download it from OTN at http://www.oracle.com/technetwork/database/databasetechnologies/instant-client/downloads/index.html For simplicity and to facilitate a direct download to your linux host, you can clone this git repository to your host machine $ git clone https://github.com/kbhanush/instantclient_12_2_linux We then unzip and move the files to /opt/oracle/instantclient_12_2 $ cd instantclient_12_2_linux/ $ unzip instantclient-basiclite-linux.x64-12.2.0.1.0.zip $cd cd instantclient_12_2/ $ sudo mv /home/opc/instantclient_12_2_linux/instantclient_12_2/ /opt/oracle/instantclient_12_2/ If there is no other Oracle software on the machine that will be impacted, then permanently add Instant Client to the run-time link path. For example, with sudo or as the root user: $ sudo sh -c "echo /opt/oracle/instantclient_12_2 > /etc/ld.so.conf.d/oracle-instantclient.conf" $ sudo ldconfig OR - set LD_LIBRARY_PATH in your bash_profile as $export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH
Install node oracle drivers through npm Next, lets download our sample node.js app from git $git clone https://github.com/kbhanush/atpnodeapp In the node.js app folder we install the node oracle drivers from npm $ cd ATPnodeapp $ npm install oracledb Your sample application consists of 2 files, dbconfig.js and server.js Set dbuser, dbpassword and connectstring in dbconfig.js to point to your ATP database module.exports= { dbuser:"adminr", dbpassword:"xxxxxxxx", connectstring :"nodeappdb2_high" } Upload connection wallet and run sample app Finally, lets upload the connection wallet and run our sample app! From your local machine, $ scp -i ~/priv-ssh-keyfile wallet_nodeappdb.zip opc@ipaddress:/home/opc/atpnodeapp ssh back into your linux host and unzip wallet into a folder /home/opc/atpnodeapp/wallet_nodeappdb $ unzip wallet_nodeappdb2.zip -d wallet_nodeappdb/ set env variable TNS_ADMIN to point to the wallet folder and edit sqlnet.ora file in the wallet folder to point to the wallet as well $ export TNS_ADMIN="/home/opc/ATPnodeapp/wallet_NODEAPPDB/
Edit /home/opc/atpnodeapp/wallet_nodeappdb/sqlnet.ora as follows WALLET_LOCATION = (SOURCE = (METHOD = file) (METHOD_DATA = (DIRECTORY=$TNS_ADMIN))) SSL_SERVER_DN_MATCH=yes That s it. Get into your node app folder, run app in background and test with curl $ node server.js & $ curl http://localhost:3050 The application confirms connectivity to your ATP instance with this message Connection test succeeded. You connected to ATP as admin!