4

Last few weeks I had been trying to connect oracle db from my nodejs code. What I found so far are 2 main libraries such as https://github.com/mariano/node-db-oracle which is out of date (last update was year ago) and second one is https://github.com/nearinfinity/node-oracle which is really up to date, however I didn't manage to connect oracle with any of those modules.

Mayor issue that npm install oracle //pr db-oracle fails due to

../src/connection.h:10:18: fatal error: occi.h: No such file or directory

I tried to clone the code and perform local install and then copy entire module under my project, install wen well, but when I place module under my project I run into this error

    module.js:340
    throw err;
          ^
Error: Cannot find module './build/Release/oracle_bindings'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/var/www/node-test/node_modules/db-oracle/db-oracle.js:18:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

I had been follow installation procedure for both drivers and had been setup variables like this (/var/environment)

OCI_HOME=/opt/instantclient_12_1
OCI_VERSION=12
OCI_INCLUDE_DIR=/opt/instantclient_12_1/sdk/include
OCI_LIB_DIR=/opt/instantclient_12_1
LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client/lib

I used ubuntu 12.04, and node version is v0.10.18 here is my sample nodejs test file:

var oracle = require('oracle');


new oracle.Database({
    hostname: 'myserver.com',
    port: 1521,
    user: 'myuser',
    password: 'mypass',
    database: 'XE'
}).connect(function(error) {
    if (error) {
        return console.log("CONNECTION ERROR: " + error);
    }
    this.query("select * FROM `store`").execute(function(error, rows) {
        if (error) {
            return console.log('ERROR: ' + error);
        }
        console.log(rows.length + ' ROWS');
    });
});

any additional hint would be nice. I tried noradle (https://github.com/kaven276/noradle) that one seems to be to heavy for my purpose.

0

4 Answers 4

5

I know this is an old post... just wanted to mention a sure way for nodejs to communicate to oracle without extra modules.

Set up oracle so it can create and receive http requests. There are a few ways to do this:

The easiest is to turn on the epg gateway:

Also you can setup modplsq:

or the Apex listener:

Then in node js do a standard http.get:

http.get("http://localhost/accessor/myschema.my_procedure?x=1&y=2", function(res) {
    console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
   console.log("Got error: " + e.message);

});

Whichever approach...secure oracle so that it will only respond to the ip address of the nodejs server. So if running on localhost:

if owa_util.get_cgi_env('REMOTE_ADDR') = '127.0.0.1' then 
   --ok
else
   -- fail
end if;

Also block calls to every other package and procedure. There are few ways to do this depending on the path you take.

Make sure you do this at a minimum:

  • create a white list of items which can be called from the web
  • require that all urls contain the schema name such as: myuser.myprocedure
  • make sure the first portion of the url (up to the query path) contains a-z 0-9 only
  • really a good white list will take care of most of these items

There you have it...no need to worry if a module will break or stop working with the next release.

AND...you can easily communicate from Oracle to Node use:

  • apex_web_service.make_rest_request
  • utl_http
Sign up to request clarification or add additional context in comments.

Comments

0

Did you get the Instant Client as described here? If I'm reading this correctly, you need the Basic (or Basic Lite) and SDK Instant Client packages. The SDK package might have the header file you're having trouble with.

Side note: in my experience, you don't always need to add Instant Client to PATH; you can usually get away with just making sure your executable can find it (which often means just dropping it in the same directory).

2 Comments

actually I recently manage to connect to Oracle. PATHs were problems.
@vaske I try to avoid putting Oracle stuff on my path. It tends to become a problem when a different project needs a different client. Good luck.
0

Set the oracle client path in the command prompt like below before starting the Node application

Set PATH=C:\oraclexe\app\oracle\instantclient_12_1;%PATH%

I had the above problem , this resolved mine and I am now able to connect to oracle .

But the one problem I am still facing is executing the select statement .It always returns error. I am able to execute SP, create statements and everything else without error . I am stuck here and sort of disappointed .

Comments

0

From what I understand, Set PATH puts the string you specified at the beginning of your Path environment variable. I entered the instant client folder path at the beginning.

C:\oraclexe\app\oracle\instantclient_12_1;

It fixed the oracle binding error, but the queries wouldn't work. Then, I added the vc11 folder path BEFORE the instant client path, so it looks like this :

C:\oraclexe\app\oracle\instantclient_12_1\vc11;C:\oraclexe\app\oracle\instantclient_12_1;

Now my queries work!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.