Posts

Showing posts with the label Mainframe

Connecting to Db2 with node-ibm_db

Image
To connect to Db2 with node-ibm_db, you will need to set a connection string, which will include information for connection such as your database name (Datasource name or DSN) and authentication credentials. An example connection string would look like this: const connStr = ‘DSN=[YOUR_DATASOURCE_NAME];UID=[YOUR_UID];PWD=xxxxxxx’ Or an alternate way would be setting the environment variable: export IBM_DB_DBNAME=[YOUR_DATASOURCE_NAME] export IBM_DB_UID=[YOUR_UID] export IBM_DB_PWD=”xxxxxxx” You can open the connection with the connection string: ibmdb.open(connStr, function (err, conn) { //… }); Or you can open the connection synchronously: const conn = ibmdb.openSync(connStr); Querying You can query Db2 by calling the query method on the Database object, which is returned after successfully opened a connection: ibmdb.open(connStr, function (err, conn) { conn.query(‘create table mytab1 (c1 int, c2 varchar(10));’, function (err, data) { ...

node-ibm_db installation

Although Node.js needs no introduction allow me to give you a brief overview :  Node.js  is a JavaScript runtime powered by Chrome’s V8 JavaScript engine. Its signature event-driven, non-blocking I/O model makes it lightweight and efficient. With over a million npm packages currently available, Node.js is currently one of the most popular frameworks for backend development on the market. Most of the things that you want to do in your Node.js application are probably covered by one of the million packages already available in the Node.js community. In our case, we want to connect to IBM Db2 with SDK for Node.js all within z/OS, and we have a npm package to do that:  node-ibm_db . Prerequisites Install IBM SDK for Node.js – z/OS To install Node.js on z/OS, you need  IBM SDK for Node.js – z/OS ® , which is available for download  here . Follow the  installation instructions on IBM Knowledge Center  to install SDK for Node.js – z/OS. Db2 and O...