Creating a Sandbox for Learning Node.js and Oracle Database

By May 3, 2017 Uncategorized

With Oracle Database 18.3 and Node.js 10 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

The first thing you’ll want to do is install VirtualBox 6.0 or later. What is VirtualBox? From the VirtualBox landing page:

VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. Not only is VirtualBox an extremely feature rich, high performance product for enterprise customers, it is also the only professional solution that is freely available as Open Source Software under the terms of the GNU General Public License (GPL) version 2.

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. Navigate to the Database App Development VM page where you’ll see a list of the included software.

Check out all the goodies in that VM! Note that Oracle Database 18.3 includes a number of enhancements for working with JSON data. See the Database JSON Developer’s Guide for details and give them a go once the VM is up and running.

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 DeveloperDaysVM2018-10-16_09.ova file you downloaded and click Continue.

On the next screen, click Import, accept the license agreement, and then the import process will begin. After a few minutes, you should see the following screen.

Select the newly imported VM on the left and then 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:

Run the following commands as the root user:

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!

Now run the following commands:

Running other examples only requires node followed by the name of the example you’d like to run:

Enjoy your new sandbox!

5 Comments

  • Omar Sawalhah says:

    Hi Dan,
    I followed the steps, and I got this warning
    npm WARN enoent ENOENT: no such file or directory, open ‘/u01/userhome/oracle/projects/oracledb-examples/package.json’
    no file is there, but
    >node select1.js
    worked fine, I tried to execute
    >node select2.js
    module.js:471
    throw err;
    ^

    Error: Cannot find module ‘async’
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/u01/userhome/oracle/projects/oracledb-examples/select2.js:31:13)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

    • danmcghan says:

      Interesting… Seems there’s a dependency, but there’s no package.json file in the examples directory. Open a terminal, change directories to where the examples are, then run the following to create the package.json: npm init -y. Then run this to install async: npm install async --save. The --save will add async to the list of dependencies in the package.json file.

  • Omar Sawalhah says:

    Thanks Dan,
    Worked fine.

  • Christopher Jones says:

    An alternative way to install Node.js on Oracle Linux 7 is to use the RPMs from http://yum.oracle.com/oracle-linux-nodejs.html

    After creating a file /etc/yum.repos.d/ol7_developer_nodejs8.repo with the following contents, you can simply run ‘yum install nodejs’

    [ol7_developer_nodejs8]
    name=Oracle Linux $releasever Node.js 8 Packages for Development and test ($basearch)
    baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/developer_nodejs8/$basearch/
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
    gpgcheck=1
    enabled=1

  • Pia Cainglet says:

    Thank you! This is only the second tutorial I came across that I was able to get to work first time around. Worked like a charm. Running on a Win 7 machine (personally built).

Leave a Reply