Setup for Node.js

You need to install the node-oracledb driver to successfully configure a connection to a TimesTen database in Node.js.

Task 1: Install the node-oracledb Driver

There are several approaches for installing the node-oracledb driver. Choose the approach that is most suitable for your setup and environment.

Information for all scenarios is available at Installing node-oracledb.

Task 2: Initialize the node-oracledb Driver

By default, the node-oracledb driver runs in Thin mode which connects directly to Oracle Database. However, to connect to a TimesTen database, the driver needs to be in Thick mode so it uses the Oracle Instant Client library included with TimesTen.

To enable Thick mode for the node-oracledb driver, call the oracledb.init_oracle_client() synchronous function in your application before creating any connection. See Enabling node-oracledb Thick Mode.

This example calls the oracledb.init_oracle_client() function without a libDir attribute to ensure it uses the PATH environment variable set by ttenv script. See Task 2: Set the TimesTen Environment.

var oracledb = require('oracledb');
oracledb.initOracleClient();

Task 3: Configure Connections to TimesTen in Node.js

You can use a TNS name or an Easy Connect mechanism to connect to your database. See Task 4: Configure Connections for TimesTen.

This example uses a TNS name for a Node.js connection string:

function connect(cb) {
    oracledb.getConnection({
      user          :  "appuser",
      password      :  "password",
      connectString :  "sampledbconn"
    } ,
    cb);
}

This example uses an Easy Connect string that specifies a direct connection to TimesTen:

function connect(cb) {
    oracledb.getConnection({
      user          : "appuser",
      password      : "password",
      connectString : "myhost/sampledb:timesten_direct"
    } ,
    cb);
}