Rached Nemr
Rached Nemr

Reputation: 11

nodejs oracle improve ability

i am using node-oracleDB connector to connect to my local database , and i want to ask if it was an other(optimal) way to connect to the database, in order to improve communication ability between nodejs and oracle. thanks

Upvotes: 0

Views: 81

Answers (2)

Christopher Jones
Christopher Jones

Reputation: 10566

Node-oracledb is the connector to use when writing Node.js applications that need to connect to Oracle Database.

Most apps will want to use a connection pool

var oracledb = require('oracledb');

oracledb.createPool (
  {
    user          : "hr"
    password      : "welcome"
    connectString : "localhost/XE"
  },
  function(err, pool)
  {
    pool.getConnection (
      function(err, connection)
      {
        // use the connection
        connection.execute(. . .

          // release the connection when finished
          connection.close(
            function(err)
            {
              if (err) { console.error(err.message); }
            });
          });
      });
  });

There are some simplifications such as the 'default' connection pool that make it easier to share a pool across different modules. This is all covered in the documentation.

Upvotes: 0

I think using connection pooling is the good way. You can find some examples of pooling at here.

Please look at this file https://github.com/oracle/node-oracledb/blob/master/test/pool.js and read carefully to understand how handling connections in a pool.

Upvotes: 1

Related Questions