The Oracle connector enables LoopBack applications to connect to Oracle data sources.
Page Contents


Oracle is an object-relational database management system produced by Oracle Corporation. The loopback-connector-oracle module is the Oracle connector for the LoopBack framework based on the node-oracledb module.

For more information, see the LoopBack documentation.


Node.js: The Oracle connector requires Node.js version 4.x or 6.x.

Windows: On 32-bit Windows systems, you must use the 32-bit version of Node.js. On 64-bit Windows systems, you must use the 64-bit version of Node.js. For more information, see Node-oracledb Installation on Windows.

Oracle: The Oracle connector requires Oracle client libraries 11.2+ and can connect to Oracle Database Server 9.2+.


In your application root directory, enter this command to install the connector:

$ npm install loopback-connector-oracle --save

If you create a Oracle data source using the data source generator as described below, you don’t have to do this, since the generator will run npm install for you.

See Installing the Oracle connector for further installation instructions.

To simplify the installation of node-oracledb module and Oracle instant clients, use loopback-oracle-installer as a dependency to install and configure node-oracledb (oracledb) upon npm install.

Use the config.oracleUrl property to define the base URL to download the corresponding node-oracle (oracledb) bundle for the local environment.

The bundle file name is loopback-oracle-<platform>-<arch>-<version>.tar.gz. The version is the same as the version in package.json.

  "dependencies": {
      "loopback-oracle-installer": "git+ssh://",
  "config": {
      "oracleUrl": ""

You can override the oracleUrl setting with the LOOPBACK_ORACLE_URL environment variable.

For example, the full URL for v1.5.0 for MacOSX is:

The libaio library is required on Linux systems:

On Ubuntu/Debian, get it with this command:

sudo apt-get install libaio1

On Fedora/CentOS/RHEL, get it with this command:

sudo yum install libaio

Creating an Oracle data source

Use the Data source generator to add a Oracle data source to your application.
The generator will prompt for the database server hostname, port, and other settings required to connect to a Oracle database. It will also run the npm install command above for you.

The entry in the application’s /server/datasources.json will look like this:


"mydb": {
  "name": "mydb",
  "connector": "oracle",
  "tns": "demo",  
  "host": "myserver",
  "port": 3306,
  "database": "mydb",
  "password": "mypassword",
  "user": "admin"

Edit datasources.json to add any other additional properties that you require.

Connector properties

The connector properties depend on naming methods you use for the Oracle database. LoopBack supports three naming methods:

  • Easy connect: host/port/database.
  • Local naming (TNS): alias to a full connection string that can specify all the attributes that Oracle supports.
  • Directory naming (LDAP): directory for looking up the full connection string that can specify all the attributes that Oracle supports.

Easy Connect

Easy Connect is the simplest form that provides out-of-the-box TCP/IP connectivity to databases. The data source then has the following settings.

Property Type Default Description
host or hostname String localhost Host name or IP address of the Oracle database server
port Number 1521 Port number of the Oracle database server
username or user String   User name to connect to the Oracle database server
password String   Password to connect to the Oracle database server
database String XE Oracle database listener name

For example:


  "demoDB": {
    "connector": "oracle",
    "host": "",
    "port": 1521,
    "database": "XE",
    "username": "demo",
    "password": "L00pBack"

Local and directory naming

Both local and directory naming require that you place configuration files in a TNS admin directory, such as /oracle/admin.


This specifies the supported naming methods; for example:



This maps aliases to connection stringsl for example:



This configures the LDAP server.


Set up TNS_ADMIN environment variable

For the Oracle connector to pick up the configurations, you must set the environment variable ‘TNS_ADMIN’ to the directory containing the .ora files.

export TNS_ADMIN=<directory containing .ora files>

Now you can use either the TNS alias or LDAP service name to configure a data source:

var ds = loopback.createDataSource({
  "tns": "demo", // The tns property can be a tns name or LDAP service name
  "username": "demo",
  "password": "L00pBack"

Connection pooling options

Property name Description Default value
minConn Maximum number of connections in the connection pool 1
maxConn Minimum number of connections in the connection pool 10

Incremental number of connections for the connection pool.

timeout Time-out period in seconds for a connection in the connection pool. The Oracle connector will terminate connections in this connection pool that are idle longer than the time-out period. 10

For example,


  "demoDB": {
    "connector": "oracle",
    "timeout": 10,

Connection troubleshooting

If you encounter this error:

Error: ORA-24408: could not generate unique server group name

Then the Oracle 11g client requires an entry with your hostname pointing to

To resolve:

Get your hostname. Check your hostname by running this command (for example, if your machine’s name is “earth”):

$ hostname

Update /etc/hosts and map to your hostname “earth”:

... localhost earth

Verify the fix. Run the example in examples/app.js:

$ node examples/app.js

For more information, see StackOverflow question.

Model properties

An Oracle model definition consists of the following properties:

  • name: Name of the model, by default, it’s the camel case of the table.
  • options: Model-level operations and mapping to Oracle schema/table.
  • properties: Property definitions, including mapping to Oracle column.



Type mapping

See LoopBack types for details on LoopBack’s data types.

JSON to Oracle Types

LoopBack Type Oracle Type
Default length is 1024
Timestamp TIMESTAMP(3)
Boolean CHAR(1)

Oracle Types to JSON

Oracle Type LoopBack Type
CHAR(1) Boolean
LONG, BLOB, CLOB, NCLOB Node.js Buffer object

Discovery and auto-migration

Model discovery

The Oracle connector supports model discovery that enables you to create LoopBack models based on an existing database schema using the unified database discovery API. For more information on discovery, see Discovering models from relational databases.

For an example of model discover, see example/app.js.


The Oracle connector also supports auto-migration that enables you to create a database schema from LoopBack models using the LoopBack automigrate method.

For more information on auto-migration, see Creating a database schema from models for more information.

LoopBack Oracle connector creates the following schema objects for a given model:

  • A table, for example, PRODUCT
  • A sequence for the primary key, for example, PRODUCT_ID_SEQUENCE
  • A trigger to generate the primary key from the sequnce, for example, PRODUCT_ID_TRIGGER

Destroying models may result in errors due to foreign key integrity. First delete any related models by calling delete on models with relationships.

Running tests

The tests in this repository are mainly integration tests, meaning you will need to run them using our preconfigured test server.

  1. Ask a core developer for instructions on how to set up test server credentials on your machine
  2. npm test
Tags: connectors