Use Oracle Database with Django

In order to connect your Node.js application to an Oracle Database, you need to install the following packages.

  • libaio
  • Oracle Instant Client (and SDK)
  • oracledb Node.js module

Step 1: Install libaio

  • Execute the following command:

    $ sudo apt-get install libaio1

Step 2: Install Oracle Instant Client and Oracle Instant Client SDK

  • Download both instantclient-basic-linux.x64.zip and instantclient-sdk-linux.x64.zip. The version will depend on the Oracle Database you have running. For instance, for Oracle Database 12c you would download instantclient-basic-linux.x64- and instantclient-sdk-linux.x64- (we will use them in the rest of the examples).

  • Uncompress instantclient-basic-linux.x64.zip by executing the following command:

    $ unzip instantclient-basic-linux.x64-
  • Copy the extracted contents to /opt/bitnami/common/lib:

    $ sudo cp -r instantclient_12/* /opt/bitnami/common/lib
  • Execute the following command:

    $ sudo ln -s /opt/bitnami/common/lib/libclntsh.so.12.1 /opt/bitnami/common/lib/libclntsh.so
  • Extract instantclient-sdk-linux.x64-

    $ unzip instantclient-sdk-linux.x64-
  • Copy the contents of the sdk subfolder to /opt/bitnami/common/include:

    $ sudo cp -r instantclient_12/sdk/include/* /opt/bitnami/common/include

Step 3: Install OracleDB Node.js module

  • Before installing, set the following environment variables:

    $   export OCI_LIB_DIR=/opt/bitnami/common/lib
    $   export OCI_INC_DIR=/opt/bitnami/common/include
  • In your Node.js application folder, execute the following command:

    $   npm install oracledb

Step 4: Test the connection

In order to test that the plugin was installed correctly, execute one of the examples detailed in the OracleDB Node.js module documentation.

  • Download this example from the OracleDB Node.js module website.

  • In the same folder where connect.js was downloaded, create the file dbconfig.js with the following contents (remembering to replace the DATABASE_USER, DATABASE_PASSWORD and DATABASE_CONNECTION_STRING placeholders with the correct values):

    module.exports = {
        user          : "DATABASE_USER",
        password      : "DATABASE_PASSWORD",
        connectString : "DATABASE_CONNECTION_STRING"

    For example:

    module.exports = {
        user          : "SYSTEM",
        password      : "mypassword",
        connectString : ""
  • Run the testing program:

    $ node example.js

If everything was correct, you should see the message “Connection was successful!”