Getting error while connection to Ibm_db2 from a Node js platform - node.js

I am trying to connect to a DB2 server but I am getting bellow given error.
I'm following the given documentation: npm db2 Doc
I have done npm i ibm_db2
Code:
const ibmdb = require('ibm_db');
const connectQuery =
'DATABASE=' +
DATABASE +
';HOSTNAME=' +
HOSTNAME +
';UID=' +
UID +
';PWD=' +
PWD +
';PORT=' +
PORT +
';PROTOCOL=TCPIP';
ibmdb.open(connectQuery, function(err, conn) {
if (err) return console.log(err);
conn.query('select 1 from sysibm.sysdummy1', function(err, data) {
if (err) console.log('err');
else console.log('data');
conn.close(function() {
console.log('done');
});
});
});
Error:
Error: Could not locate the bindings file. Tried:
→ ...\node_modules\ibm_db\build\odbc_bindings.node
→ ...\node_modules\ibm_db\build\Debug\odbc_bindings.node
→ ...\node_modules\ibm_db\build\Release\odbc_bindings.node
→ ...\node_modules\ibm_db\out\Debug\odbc_bindings.node
→ ...\node_modules\ibm_db\Debug\odbc_bindings.node
Is there any other node package to establish connection ?

I have the same issue on windows 10. Because your ibm_db module is not installed successfully.
Download directly clidriver generated by IBM. After setting IBM_DB_HOME environment variable to point the directory, and reinstall ibm_db module to skip downloading clidriver.

Related

Random occurrences of Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1 when running protractor tests

My protractor test cases randomly fail with this error message:
Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1
I have gone through the resources and tried all the suggested solutions:
Upgraded protractor
Ran webdriver-manager update
Upgraded chromedriver version but the issue seems to exist.
This particularly happens when I try to run all the e2e tests together.
Below is the specific versions that Im using for my project:
node - v9.2.0
protractor - Version 5.4.1
ChromeDriver 2.42.591088
Please help.
Thanks,
Neeraja
Are you using async/await in your tests?
Can you try applying patch as specified below from the same folder which contains the 'node_modules' folder by executing 'node patch.js'?
patch.js file
var fs = require('fs');
var httpIndexFile = 'node_modules/selenium-webdriver/http/index.js';
fs.readFile(httpIndexFile, 'utf8', function (err, data) {
if (err)
throw err;
var result = data.replace(/\(e.code === 'ECONNRESET'\)/g, "(e.code === 'ECONNRESET' || e.code === 'ECONNREFUSED')");
console.log(`Patching ${httpIndexFile}`)
fs.writeFileSync(httpIndexFile, result, 'utf8');});
var chromeFile = 'node_modules/selenium-webdriver/chrome.js';
fs.readFile(chromeFile, 'utf8', function (err, data) {
if (err)
throw err;
var result = data.replace(/new http.HttpClient\(url\)/g, "new http.HttpClient(url, new (require('http').Agent)({ keepAlive: true }))");
console.log(`Patching ${chromeFile}`)
fs.writeFileSync(chromeFile, result, 'utf8');});
Please see original post here -
https://github.com/angular/protractor/issues/4706#issuecomment-393004887

What is the best way to run npm packages on demand as mircoservices without installing it locally?

Let's say I have these npm packages published to npm:
service1#v1.0
service1#v2.0
service2#v1.0
each package has a single function:
function run(extraStr) {
return 'package_name_and_version' + extraStr; // i.e. service1 v1.0 extraStr
}
And I want to write nodejs code that use the packages without installing it locally
var server = require("my-server-sdk");
// get(package_name, version, function_in_package, arguments, callback)
server.get('service1', '2.0', 'run', ['app1'], (err, result) => {
console.log(result); // this should print service1 v2.0 app1
});
where my-server-sdk is an sdk that interface with my server's api where it install the required packages and cache it for later use.
What is the best way to do that? what the security concerns and how to prevent any?
this is a simple diagram for what I want
NOTE: service1#v1.0
service1#v2.0
service2#v1.0
are just examples to any packages in npm i.e. lodash
Caching example:
Let's say we have TTL equal 60 minutes.
client1 requested a function from lodash and another function from underscore at 01:00.
Now in the server lodash and underscore are installed with timestamp 01:00.
client2 requested a function from underscore at 01:30 which get used instantly because underscore is installed before but it timestamp got updated to 1:30.
At 02:01 lodash get deleted because it didn't get used on the past TTL currenttime - lodash_timestamp > TTL but underscore stays because currenttime - underscore_timestamp < TTL
So when client3 request lodash at 02:30 it get intsalled again with 02:30 as a timestamp.
There is the npmi package which gives an API to npm install.
The logic I would use is:
Get the specific package and version from npm (install if is not already installed)
Require the package inside nodejs
Run the specified method with the specified parameters
Return the results to the client
var npmi = require('npmi');
var path = require('path');
function runModule(moduleName, moduleVersion, moduleMethod, moduleMethodParams) {
return new Promise((resolve, reject) => {
var options = {
name: moduleName, // your module name
version: moduleVersion, // expected version [default: 'latest']
forceInstall: false, // force install if set to true (even if already installed, it will do a reinstall) [default: false]
npmLoad: { // npm.load(options, callback): this is the "options" given to npm.load()
loglevel: 'silent' // [default: {loglevel: 'silent'}]
}
};
options.path = './' + options.name + "#" + options.version,
npmi(options, function(err, result) {
if (err) {
if (err.code === npmi.LOAD_ERR) console.log('npm load error');
else if (err.code === npmi.INSTALL_ERR) console.log('npm install error');
console.log(err.message);
return reject(err)
}
// installed
console.log(options.name + '#' + options.version + ' installed successfully in ' + path.resolve(options.path));
var my_module = require(path.resolve(options.path, "node_modules", options.name))
console.log("Running :", options.name + '#' + options.version)
console.log("Method :", moduleMethod);
console.log("With params :", ...moduleMethodParams)
resolve(my_module[moduleMethod](...moduleMethodParams))
});
})
}
runModule('lodash', '4.10.0', 'fill', [Array(3), 2])
.then(result => console.log("Result :", result))
runModule('lodash', '3.10.0', 'fill', [Array(3), 2])
.then(result => console.log("Result :", result))
You could see now that there are 2 created folders (lodash#3.10.0 , lodash#4.10.0) indicating the package name and version.
I have made the assumptions that npm is in path and the server has the permissions to install packages in current directory, also that the "MODULE_NAME#MODULE_VERSION" is a valid folder name under the current OS.

Node.js to DB2 (using ibm_db)

I've followed the instructions: https://www.ibm.com/developerworks/community/blogs/pd/entry/using_ibm_db2_from_node_js4?maxresults=15&page=0&lang=en
for a 32-bit install of Ubuntu.
It seems to have installed correctly and I can run require('ibm_db'). Using the sample code provided (nodedb2test.js), no matter what database parameters I use I get the error:
node nodedb2test.js
Test program to access DB2 sample database
*** stack smashing detected ***: node terminated
Aborted (core dumped)
Heres the sample code:
/*require the ibm_db module*/
var ibmdb = require('ibm_db');
console.log("Test program to access DB2 sample database");
ibmdb.open("DRIVER={DB2};DATABASE=testdb;UID=username;PWD=password;HOSTNAME=localhost;port=3000", function(err, conn)
{
if(err) {
console.error("error: ", err.message);
}
});
Also I looks the version of DB2 I need to connect to is version 6. I have installed BM Data Server Driver version 10.5, does this correspond to the version of DB2? It appears below v9.1 drivers are not available.
At time of writing this works for me.
C:\Development\Javascript>node -p "process.arch"
x64
C:\Development\Javascript>node -p "process.platform"
win32
C:\Development\Javascript>node -p "process.version"
v14.17.5
C:\Development\Javascript>npm install ibm_db
var ibmdb = require("ibm_db");
const config = require("config");
const hostname = config.get("db2.hostname");
const username = config.get("db2.username");
const password = config.get("db2.password");
ibmdb.open("DRIVER={DB2};DATABASE=bludb;HOSTNAME=" + hostname + ";UID=" + username + ";PWD=" + password + ";PORT=31198;PROTOCOL=TCPIP;SECURITY=SSL", function (err, conn){
if (err) return console.log(err);
conn.query("SELECT * FROM orders", function (err, data) {
if (err) console.log(err);
console.log(data);
conn.close(function () {
console.log('done');
});
});
});
We can use ibm_db without installing IBM Data Server Driver Package too. ibm_db internally uses DB2 V10.5FP5 ODBC/CLI driver to talk to DB2 server. Please share the platform info and OS version where you have installed ibm_db. In june'14, ibm_db was supported on Linuxppc, AIX and zLinux platforms, but latest release is supporting. If latest driver is not working for you, please open an issue on github.com/ibmdb/node-ibm_db/issues/new . Thanks.

Node JS Error: Cannot find module './build/Release/mysql_bindings'

I have installed Node.Js and Casper.js to perform webscraping and save the info into a DB. But I have a problem because when I try to execute the source, I get the following error in the terminal:
Error: Cannot find module './build/Release/mysql_bindings'
I have previously installed mysql-libmysqlclient with the mysql_bindings inside. I tested creating the route of the error, but it didn't work.
The code is:
var mysql = require('db-mysql');
new mysql.Database({
hostname: 'localhost',
user: 'rool',
password: 'xxxx',
database: 'xxxBD' }).connect(function(error) {
if (error) {
return console.log('CONNECTION error: ' + error);
}
this.query().
select('*').
from('tablaPruebas').
execute(function(error, rows, cols) {
if (error) {
console.log('ERROR: ' + error);
return;
}
console.log(rows.length + ' ROWS found');
});
});
Thanks in advance!
The problem is that your using the following in your code:
var mysql = require('db-mysql');
However your question shows that you have installed mysql-libmysqlclient. This means you should be using the following instead:
var mysql = require('mysql-libmysqlclient');
I presume you installed from https://github.com/Sannis/node-mysql-libmysqlclient
The code you're using looks more like db-mysql which can be found here
If you install via npm install db-mysql then you should be good. Have a look at the link I included for db-mysql as there appears to be a few dependencies (e.g. setting up MYSQL_CONFIG environment variable).

Node.js SQL Server driver issue - How to troubleshoot

What is the correct way to troubleshoot this error with Node.js on Windows with the SQL Server driver.
events.js:2549: Uncaught Error: 42000: [Microsoft][SQL Server Native Client 11.0
]Syntax error, permission violation, or other nonspecific error
It is not the SQL statement - it works in other tools - like .NET
Doesn't seem to be the SQL connection info - it works in other tools - like .NET
Any thoughts? What is the correct way for completely uninstalling node.js and starting over. I don't think my last install removed all my global modules.
var sql = require('node-sqlserver');
var _ = require('underscore')._;
var connstr = "Driver={SQL Server Native Client 11.0};Server=localhost;" +
"Initial Catalog=CDDB;Trusted_Connection={Yes}";
sql.open(connstr, function (err, conn) {
if (err) {
console.log("Error opening the connection");
return;
} else {
var stmt = "select top 10 * from Client";
conn.query(connstr, stmt, function (err, results) {
if (err) {
console.log("Error running query!");
return;
}
_.each(results, function (row) {
console.log(row[0]);
});
});
}
});
First idea : Are users which runs your node.exe process and the one defined on your application pool - or maybe your current user account if you are using VS.NET to check your code are the same ?
To troubleshoot :
I would use node-inspector - it allows to set up breakpoints onto your node.js code
To install it :
npm install -g node-inspector
To run it :
node --debug your-nodeapp-file.js
Launch another command line and run the following program :
node-inspector
Sorry but i do not have SQL Server to try your code, hope this help anyway.

Resources