Search code examples
node.jsnode-oracledb

Hide OracleDatabase credentials in Node.js


I'm connecting to an external Oracle Database with the example function that can be found here

const oracledb = require('oracledb');

const connection = await oracledb.getConnection(
  {
    user          : "hr",
    password      : mypw,  // mypw contains the hr schema password
    connectString : "mydbmachine.example.com/orclpdb1"
  }
);

So, as you can see, my credentials would be 'exposed' to everyone who can access the code (maybe github repository or something).

Is there any way of hiding my username and password or making them confidential, or I just shouldn't worry about it?

Note: I'm using the oracledb node module


Solution

  • You could use .env, and access to it with process.env.

    check here: https://nodejs.org/dist/latest-v8.x/docs/api/process.html#process_process_env