With Oracle Database 12.2 and Node.js 8 now available, this is a great time to create a local sandbox for learning. Thanks to some prebuilt VMs provided by Oracle, you can have such an environment up and running in less than 20 minutes (excluding download times) without spending a dime! 😄
In this post, I’ll walk you through the creation of such a sandbox. Here’s an overview of what we’ll be working through:
- Install VirtualBox
- Import Database App Development VM
- Install Node.js and Git
- Install the Node.js Driver and Run a Test
VirtualBox is a cross-platform virtualization application. What does that mean? For one thing, it installs on your existing Intel or AMD-based computers, whether they are running Windows, Mac, Linux or Solaris operating systems. Secondly, it extends the capabilities of your existing computer so that it can run multiple operating systems (inside multiple virtual machines) at the same time.
VirtualBox is a great solution for this type of sandbox because we don’t have to install any software on our host operating system which would consume resources when not in use. I will not cover the installation process in any detail as it will vary depending on your host OS. Just navigate to the downloads page and download & install the appropriate binaries for your OS.
Import the Database App Development VM
Oracle provides a number of pre-built development VMs that are great for learning Oracle technology as you don’t have to muddle through complicated installs to get going. Head to the Pre-Built Developer VMs page and scroll down until you see the Database App Development VM.
Check out all the goodies in that VM! Note that Oracle Database 18.104.22.168 includes a number of enhancements for working with JSON. See the Database JSON Developer’s Guide for details and give them a go once the VM is up and running.
Click the link that says Downloads and Instructions. On the next page, accept the license agreement and then click the link to download the VM.
If you’ve not already authenticated with your Oracle account, you’ll be redirected to a page to do so before the download begins. If you don’t have an account just click the Create Account button on that page to create your free account.
Once the download completes you’ll be ready to import the VM into VirtualBox. Open VirtualBox and click File > Import Appliance. Use the appliance import wizard to select the DeveloperDaysVM2017-06-13_01 file you downloaded and click Import.
The import process will begin once you accept the license agreement. After a few minutes, you should see the following screen.
If you click the Start button a new window will open up with the VM running a terminal inside (you can resize the VM window as needed).
Here are a few tips to get you started inside the VM:
- The password for everything is: oracle
- Double-click the large START icon on the desktop to open a browser with labs on a variety of Oracle technology.
- To access APEX, navigate the browser to http://localhost:8080/apex. Log in using OBE for the workspace and username fields and oracle for the password.
- To be able to copy/paste things between the host and guest OS, go to the VirtualBox menu bar and select Devices > Shared Clipboard > Bidirectional. Trust me, this will come in handy!
With the VM up and running we’re ready to install Node.js and Git.
Install Node.js and Git
In this section, we’ll install Node.js and Git. Git will be used to install the Node.js driver for Oracle Database in the next step.
Open a terminal and switch to the root user:
su - root
# password is oracle
Run the following commands as the root user:
yum group install "Development Tools" -y
curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
yum install nodejs -y
yum install git -y
That’s all there is to it, Node.js and Git are ready to go. On to the driver!
Install the Node.js Driver and Run a Test
Example scripts for the driver can be found at: https://github.com/oracle/node-oracledb/tree/master/examples. The easiest way to start running the examples is to use Git to clone the driver repo from GitHub. From there we can copy the examples into our own directory, change the password in dbconfig.js, install the driver, and start testing!
Close the previously opened terminal and open a new one (user should be oracle). Then run the following commands:
echo 'export LD_LIBRARY_PATH=$ORACLE_HOME/lib' >> .bashrc
git clone https://github.com/oracle/node-oracledb.git
mkdir -p projects/oracledb-examples
cp node-oracledb/examples/* projects/oracledb-examples
sed -i -e 's/"welcome"/"oracle"/' dbconfig.js
npm install oracledb
Running subsequent examples only requires node followed by the name of the example you’d like to run:
Enjoy your new sandbox!