{"id":15926,"date":"2017-01-31T12:15:23","date_gmt":"2017-01-31T10:15:23","guid":{"rendered":"https:\/\/www.webcodegeeks.com\/?p=15926"},"modified":"2017-01-30T12:26:28","modified_gmt":"2017-01-30T10:26:28","slug":"building-node-module-connects-db2","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/","title":{"rendered":"Building a Node Module That Connects to DB2"},"content":{"rendered":"<p>The NPM registry contains many Node modules that help you to\u00a0connect to a wide variety of databases including MySQL, Oracle, Mongo and even IBM DB2. This article demonstrates how to write a very simple Node module that connects to DB2 using the ibm_db Node module provided by IBM.<\/p>\n<p>Key concepts covered in this article:<\/p>\n<ul>\n<li>Creating a simple Node module<\/li>\n<li>Using the <a href=\"https:\/\/www.npmjs.com\/package\/ibm_db\" target=\"_blank\">ibm_db<\/a>\u00a0module to query a DB2 database<\/li>\n<li>Creating a simple test web server to output query results to the browser<\/li>\n<li>Using <a href=\"https:\/\/nodemon.io\/\" target=\"_blank\">Nodemon<\/a> to automatically reload your Node server as you make changes<\/li>\n<\/ul>\n<blockquote><p>This article contains various code snippets. The entire\u00a0solution can be found on GitHub:\u00a0https:\/\/github.com\/briandesousa\/node-db2<\/p><\/blockquote>\n<h2>Prerequisites<\/h2>\n<p>You will need to have\u00a0the\u00a0following tools installed:<\/p>\n<ul>\n<li><a href=\"https:\/\/nodejs.org\/en\/download\/\" target=\"_blank\">Node <\/a>\u2013 I\u2019ll be using Node v6.9.4 (LTS) but technically the ibm_db module support goes as far back as Node v4.x.<\/li>\n<li><a href=\"https:\/\/www.ibm.com\/developerworks\/downloads\/im\/db2express\/\" target=\"_blank\">IBM DB2 Express-C<\/a> \u2013 This is a free version of DB2 provided by IBM. You will need to register a free account with IBM before downloading. This version of DB2 may not be available in all countries.\n<ul>\n<li>During installation, be sure to select the option to install a sample database. We will be using the sample database in this solution.<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"https:\/\/code.visualstudio.com\/\" target=\"_blank\">Visual Studio Code<\/a> is my editor of choice these days but use whatever tool you are most comfortable with to develop in JavaScript.<\/li>\n<li>A SQL client. I will be using <a href=\"https:\/\/wiki.eclipse.org\/Scout\/Tutorial\/3.8\/Database_Development_Perspective\" target=\"_blank\">Eclipse Database Development Perspective<\/a> to connect to the local DB2 server.<\/li>\n<\/ul>\n<h2>Design Overview<\/h2>\n<p>The application we will be building consists of a simple node module (node-db2-module) that uses the ibm_db node module to connect to a SAMPLE database running on a local DB2 Express-C server. We will also build a simple Node web server (node-db2-module-test) so that we can output the contents of our databse to the browser.<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/01\/node_db2_appstructure.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-15929\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/01\/node_db2_appstructure.png\" alt=\"\" width=\"523\" height=\"369\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/01\/node_db2_appstructure.png 523w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/01\/node_db2_appstructure-300x212.png 300w\" sizes=\"(max-width: 523px) 100vw, 523px\" \/><\/a><\/p>\n<h2>Setup the Database<\/h2>\n<p>The first step is to install DB2 Express-C if you haven\u2019t already. During installation, be sure to select the option to install a sample database.<\/p>\n<p>After installation is complete, use your favorite SQL client to connect to the database with the credentials provided during installation, for example:<\/p>\n<ul>\n<li>database name = SAMPLE<\/li>\n<li>user name = db2appuser<\/li>\n<li>password = password<\/li>\n<li>host = localhost<\/li>\n<li>port = 50000<\/li>\n<\/ul>\n<p>Your local database server should contain a SAMPLE database \u00a0with a default schema for your user account. Here\u2019s an example of what your database my look like on a Windows system:<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/01\/node_db2_databasestructure.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-15930\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/01\/node_db2_databasestructure.png\" alt=\"\" width=\"235\" height=\"232\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/01\/node_db2_databasestructure.png 235w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/01\/node_db2_databasestructure-70x70.png 70w\" sizes=\"(max-width: 235px) 100vw, 235px\" \/><\/a><\/p>\n<p>We\u00a0will reuse the SAMPLE\u00a0database and default schema\u00a0but create our own version of the CUSTOMER table. Execute the following SQL script:<\/p>\n<pre class=\"brush:sql\">DROP TABLE CUSTOMER;\r\n\r\nCREATE TABLE \"CUSTOMER\" (\r\n \"CID\" BIGINT GENERATED ALWAYS AS IDENTITY,\r\n \"FIRST_NAME\" VARCHAR(100),\r\n \"LAST_NAME\" VARCHAR(100));\r\n\r\nALTER TABLE \"CUSTOMER\" ADD CONSTRAINT \"PK_CUSTOMER\" PRIMARY KEY (\"CID\");\r\n\r\nINSERT INTO CUSTOMER (FIRST_NAME, LAST_NAME) VALUES ('Homer', 'Simpson');\r\nINSERT INTO CUSTOMER (FIRST_NAME, LAST_NAME) VALUES ('Marge', 'Simpson');\r\nINSERT INTO CUSTOMER (FIRST_NAME, LAST_NAME) VALUES ('Ned', 'Flanders');<\/pre>\n<h2>Building the\u00a0node-db2-module Module<\/h2>\n<p>The first Node module we will build is the node-db2-module. It contains our JavaScript code to retrieve records from the CUSTOMER table in the SAMPLE database.<\/p>\n<p><strong>package.json<\/strong><\/p>\n<p>In your workspace, create a sub-folder named node-db2-module and add the following package.json to it:<\/p>\n<pre class=\"brush:js\">{\r\n    \"name\": \"node-db2-module\",\r\n    \"version\": \"1.0.0\",\r\n    \"description\": \"An example of a Node module that communicates with a DB2 database using IBM DB2 node drivers\",\r\n    \"main\": \"index.js\",\r\n    \"scripts\": {\r\n        \"start\" : \"nodemon test.js\"\r\n    },\r\n    \"author\": \"\",\r\n    \"license\": \"ISC\",\r\n    \"private\": true,\r\n    \"dependencies\": {\r\n        \"ibm_db\": \"^1.0.1\"\r\n    },\r\n    \"devDependencies\": {\r\n        \"nodemon\": \"^1.11.0\"\r\n    }\r\n}<\/pre>\n<p>Pay particular attention to the following configurations in the package.json:<\/p>\n<ol>\n<li>The index.js script is\u00a0the main entry point for this module.<\/li>\n<li>The test.js script contains simple tests that invokes our module for testing purposes.<\/li>\n<li>We are leveraging Nodemon to monitor our module directory for file changes and re-running our tests each time a file is modified. You can initiate this process by running the\u00a0<em>npm start\u00a0<\/em>command.<\/li>\n<\/ol>\n<p><strong>index.js<\/strong><\/p>\n<p>Next, we will add the index.js script. The entire source of index.js can be found <a href=\"https:\/\/github.com\/briandesousa\/node-db2\/blob\/master\/node-db2-module\/index.js\" target=\"_blank\">here<\/a>\u00a0but I will highlight a few key snippets.<\/p>\n<p>The first thing index.js does is import two other modules:<\/p>\n<pre class=\"brush:js\">var ibmdb = require('ibm_db');\r\nvar config = require('.\/config');<\/pre>\n<p>The <em>ibmdb\u00a0<\/em>object will be used to\u00a0connect to the DB2 database. The\u00a0<em>config\u00a0<\/em>object contains database connection configuration that is defined in a separate config.json\u00a0file:<\/p>\n<pre class=\"brush:js\">{\r\n    \"database_name\" : \"SAMPLE\",\r\n    \"database_user\" : \"db2appuser\",\r\n    \"database_password\" : \"password\",\r\n    \"database_host\" : \"localhost\",\r\n    \"database_port\" : \"50000\"\r\n}<\/pre>\n<p>The index.js script also exports two different classes:<\/p>\n<ul>\n<li>Customer \u2013 A POJO (plain-old JavaScript object) class containing three\u00a0customer properties.<\/li>\n<li>CustomerDataRetriever \u2013 A\u00a0class that contains a single retrieveCustomers() method that accepts a callback function. The method asynchronously opens a DB2 connection, retrieves all customer records from the database and returns the results in a collection of Customer objects back through a parameter accepted by the callback function. The source of the retrieveCustomers()\u00a0method is shown below.<\/li>\n<\/ul>\n<pre class=\"brush:js\">retrieveCustomers(callback) {\r\n        var customers = [];\r\n        console.log(\"Opening DB2 connection\");\r\n\r\n        var connString = \"DRIVER={DB2};\"\r\n            + \"DATABASE=\" + config.database_name + \";\"\r\n            + \"UID=\" + config.database_user + \";\"\r\n            + \"PWD=\" + config.database_password + \";\"\r\n            + \"HOSTNAME=\" + config.database_host + \";\"\r\n            + \"port=\" + config.database_port;\r\n\r\n        console.log(\"DB2 connection string: \" + connString);\r\n\r\n        ibmdb.open(connString, function(err, conn) {\r\n            if(err) {\r\n          \t    console.log(\"DB2 connection error: \", err.message);\r\n                callback();\r\n            } else {\r\n                conn.query(\"select * from customer fetch first 100 rows only\", function(err, customerRows, moreResultSets) {\r\n                    if(err) {\r\n                        console.log(\"DB2 query failed: \", err.message);\r\n                    } else {\r\n                        for(var i = 0; i &lt;; customerRows.length; i++) {\r\n                            customers.push(\r\n                                new module.exports.Customer(\r\n                                    customerRows[i].CID,\r\n                                    customerRows[i].FIRST_NAME,\r\n                                    customerRows[i].LAST_NAME));\r\n                        }\r\n\r\n                        if(typeof callback === \"function\") {\r\n                            callback(customers);\r\n                        }\r\n                    }\r\n                });\r\n\r\n                conn.close(function(){\r\n                    console.log(\"DB2 connection Closed\");\r\n                });\r\n            }\r\n        });\r\n    }<\/pre>\n<p>We are using the ibmdb.open() function to open a connection to DB2 in an asynchronous fashion (passing it a callback function). The ibm_db module provides methods for connecting to DB2 synchronously but in true Node non-blocking IO fashion, we will keep everything asychronous for this example.<\/p>\n<p>Aside from the asynchronous nature of the DB2 connection code, everything else should look similar to your typical connection logic written in other languages such as Java:<\/p>\n<ol>\n<li>The connection is opened. The driver, database name, username, password, host and port are all required to open a connection. I am pulling these values from <em>config.json<\/em>.<\/li>\n<li>A SQL query is executed using the open connection.<\/li>\n<li>The query results are mapped to an object. The result set returned by ibmdb is an array containing objects with properties named after columns \u00a0in the table.<\/li>\n<li>The connection is closed.<\/li>\n<\/ol>\n<p><strong>test.js<\/strong><\/p>\n<p>The test.js script contains a simple integration test to validate the functions in the index.js script:<\/p>\n<pre class=\"brush:js\">var nodeDB2 = require('.\/index.js');\r\nvar dataRetriever = new nodeDB2.CustomerDataRetriever();\r\nvar receivedCustomers = false;\r\n\r\ndataRetriever.retrieveCustomers(function(customers) {\r\n    receivedCustomers = true;\r\n    if(Array.isArray(customers)) {\r\n        for(var i = 0; i &lt; customers.length; i++) {\r\n            console.log(\"[\" + customers[i].customerId + \"] \" + customers[i].firstName + \" \" + customers[i].lastName);\r\n        }\r\n    } else {\r\n        console.log(\"Customer list could not be retrieved\");\r\n    }\r\n});\r\n\r\ncontinueExec();\r\n\r\nfunction continueExec() {\r\n    if(!receivedCustomers) {\r\n        setTimeout(continueExec, 1000);\r\n    }\r\n}<\/pre>\n<p>We have to include a little timeout logic to wait for CustomerDataRetriever to return results since CustomerDataRetriever is designed to run asynchronously but we want our integration test to output the results as soon as they are ready.<\/p>\n<h2>Building the\u00a0node-db2-module-test Module<\/h2>\n<p>This module contains a very simple Node web server that leverages CustomerDataRetriever in the node-db2-module to retrieve a list of customers and display them in a nicely formatted table in the browser. The final result look like this in a browser:<\/p>\n<p><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/01\/node_db2_customerlist.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-15931\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/01\/node_db2_customerlist.png\" alt=\"\" width=\"676\" height=\"237\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/01\/node_db2_customerlist.png 676w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/01\/node_db2_customerlist-300x105.png 300w\" sizes=\"(max-width: 676px) 100vw, 676px\" \/><\/a><\/p>\n<p><strong>package.json<\/strong><\/p>\n<p>Once again we are going to create another sub-folder in the workspace for the node-db2-module-test module. Within that sub-folder, create a package.json with the following contents:<\/p>\n<pre class=\"brush:js\">{\r\n  \"name\": \"node-db2-module-test\",\r\n  \"version\": \"1.0.0\",\r\n  \"description\": \"Test harness for Node DB2 module\",\r\n  \"main\": \"test.js\",\r\n  \"scripts\": {\r\n    \"start\" : \"nodemon testServer.js\"\r\n  },\r\n  \"author\": \"Brian De Sousa &lt;briandesousa1@gmail.com&gt; (briandesousa1.wordpress.com)\",\r\n  \"license\": \"ISC\",\r\n  \"private\": true,\r\n  \"dependencies\": {\r\n    \"node-db2-module\": \"..\\\\node-db2-module\\\\\",\r\n    \"require\": \"^2.4.20\"\r\n  },\r\n  \"devDependencies\": {\r\n    \"nodemon\": \"^1.11.0\"\r\n  }\r\n}<\/pre>\n<p>Similar to the previous module\u2019s package.json, we are going to use nodemon to detect changes to our scripts in the module directory and automatically reload the Node server as needed. The\u00a0<em>npm start<\/em> command is used to initiate this process.<\/p>\n<p>The package.json has a dependency on the node-db2-module so that it can make use of the CustomerDataRetriever.<\/p>\n<p><strong>testServer.js<\/strong><\/p>\n<p>The last piece of the puzzle is the Node server itself.\u00a0The testServer.js will defined a very basic Node web server that listens on port 8080:<\/p>\n<pre class=\"brush:js\">console.log(\"Initializing node-db2-module\");\r\n\r\nvar http = require('http');\r\nvar nodeDB2 = require('node-db2-module');\r\n\r\nvar customers = [];\r\n\r\nvar header = `\r\n  &lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;link href=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.7\/css\/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz\/K68vbdEjh4u\" crossorigin=\"anonymous\"&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;h1&gt;Customers&lt;\/h1&gt;\r\n    &lt;table class=\"table\"&gt;\r\n    &lt;tr&gt;\r\n      &lt;th&gt;Customer ID&lt;\/th&gt;\r\n      &lt;th&gt;First Name&lt;\/th&gt;\r\n      &lt;th&gt;Last Name&lt;\/th&gt;\r\n      &lt;th&gt;&lt;\/th&gt;\r\n    &lt;tr&gt;`;\r\n\r\nvar footer = `&lt;\/table&gt;\r\n  &lt;\/body&gt;\r\n  &lt;\/html&gt;`;\r\n\r\n\/\/ retrieve customer records using node-db2-module package\r\nvar dataRetriever = new nodeDB2.CustomerDataRetriever();\r\ndataRetriever.retrieveCustomers(function(customerList) {\r\n    console.log(\"Size of customer list that was retrieved: \" + customerList.length);\r\n    customers = customerList;\r\n});\r\n\r\n\/\/ create web server and output customer records HTML\r\nhttp.createServer(function(request, response) {\r\n    var html = header;\r\n    console.log(customers.length);\r\n\r\n    customers.forEach(function(customer) {\r\n      html += \"&lt;tr&gt;&lt;td&gt;\" + customer.customerId + \"&lt;\/td&gt;\";\r\n      html += \"&lt;td&gt;\" + customer.firstName + \"&lt;\/td&gt;\";\r\n      html += \"&lt;td&gt;\" + customer.lastName + \"&lt;\/td&gt;\";\r\n      html += `&lt;td&gt;\r\n                 &lt;button&gt;Edit&lt;\/button&gt;\r\n                 &lt;button&gt;Delete&lt;\/button&gt;\r\n               &lt;\/td&gt;\r\n             &lt;\/tr&gt;`;\r\n    });\r\n\r\n    html += footer;\r\n    response.end(html);\r\n}).listen(8080, 'localhost');\r\n\r\nconsole.log(\"Web server running at http:\/\/localhost:8080\");<\/pre>\n<p>For the purposes of this article, I have demonstrated the creation of a very simple Node web server here. There are numerous better frameworks and ways of building a full-featured web server (for example the Express web application framework).<\/p>\n<p>The testServer.js imports the node-db2-module that we created earlier, creates and instance of the CustomerDataRetriever class and uses it to retrieve a collection of Customer objects. Then a simple web server is created and some dynamic HTML is produced to output the Customer array to the browser in a nicely-formatted table.<\/p>\n<h2>Final Thoughts<\/h2>\n<p>The ibm_db modules proved to be a very easy to use Node module. Very little boiler plate code is required to setup a database connection. The ibm_db module also supports all the typical capabilities that you would expect from a typical relational database interface such as the ability to invoke stored procedures and transactions. More information is available on the <a href=\"https:\/\/github.com\/ibmdb\/node-ibm_db\" target=\"_blank\">ibm_db GitHub repository<\/a>.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"https:\/\/briandesousa1.wordpress.com\/2017\/01\/29\/building-a-node-module-that-connects-to-db2\/\">Building a Node Module That Connects to DB2<\/a> from our <a href=\"http:\/\/www.webcodegeeks.com\/join-us\/wcg\/\">WCG partner<\/a> Brian De Sousa at the <a href=\"https:\/\/briandesousa1.wordpress.com\/\">Brian De Sousa&#8217;s blog<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The NPM registry contains many Node modules that help you to\u00a0connect to a wide variety of databases including MySQL, Oracle, Mongo and even IBM DB2. This article demonstrates how to write a very simple Node module that connects to DB2 using the ibm_db Node module provided by IBM. Key concepts covered in this article: Creating &hellip;<\/p>\n","protected":false},"author":141,"featured_media":924,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-15926","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Building a Node Module That Connects to DB2 - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"The NPM registry contains many Node modules that help you to\u00a0connect to a wide variety of databases including MySQL, Oracle, Mongo and even IBM DB2. This\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building a Node Module That Connects to DB2 - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"The NPM registry contains many Node modules that help you to\u00a0connect to a wide variety of databases including MySQL, Oracle, Mongo and even IBM DB2. This\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-31T10:15:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Brian De Sousa\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@briandesousa1\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Brian De Sousa\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/\"},\"author\":{\"name\":\"Brian De Sousa\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b3add10a27821f3334ef6ea4517afa38\"},\"headline\":\"Building a Node Module That Connects to DB2\",\"datePublished\":\"2017-01-31T10:15:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/\"},\"wordCount\":1249,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"articleSection\":[\"Node.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/\",\"name\":\"Building a Node Module That Connects to DB2 - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"datePublished\":\"2017-01-31T10:15:23+00:00\",\"description\":\"The NPM registry contains many Node modules that help you to\u00a0connect to a wide variety of databases including MySQL, Oracle, Mongo and even IBM DB2. This\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Node.js\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/node-js\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Building a Node Module That Connects to DB2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b3add10a27821f3334ef6ea4517afa38\",\"name\":\"Brian De Sousa\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e6d9ee737fde3578595268395d83bed5675158601972fb206794255c46798404?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e6d9ee737fde3578595268395d83bed5675158601972fb206794255c46798404?s=96&d=mm&r=g\",\"caption\":\"Brian De Sousa\"},\"description\":\"Brian De Sousa is a senior software developer working in the financial industry. He has over 10 years of experience developing web applications with a variety of web technologies. He has a passion for developing solutions using the latest and greatest technologies and frameworks.\",\"sameAs\":[\"https:\/\/briandesousa1.wordpress.com\/\",\"https:\/\/www.linkedin.com\/in\/briandesousa?trk=hp-identity-name\",\"https:\/\/x.com\/briandesousa1\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/brian-de-sousa\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Building a Node Module That Connects to DB2 - Web Code Geeks - 2026","description":"The NPM registry contains many Node modules that help you to\u00a0connect to a wide variety of databases including MySQL, Oracle, Mongo and even IBM DB2. This","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/","og_locale":"en_US","og_type":"article","og_title":"Building a Node Module That Connects to DB2 - Web Code Geeks - 2026","og_description":"The NPM registry contains many Node modules that help you to\u00a0connect to a wide variety of databases including MySQL, Oracle, Mongo and even IBM DB2. This","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2017-01-31T10:15:23+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","type":"image\/jpeg"}],"author":"Brian De Sousa","twitter_card":"summary_large_image","twitter_creator":"@briandesousa1","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Brian De Sousa","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/"},"author":{"name":"Brian De Sousa","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b3add10a27821f3334ef6ea4517afa38"},"headline":"Building a Node Module That Connects to DB2","datePublished":"2017-01-31T10:15:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/"},"wordCount":1249,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","articleSection":["Node.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/","name":"Building a Node Module That Connects to DB2 - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","datePublished":"2017-01-31T10:15:23+00:00","description":"The NPM registry contains many Node modules that help you to\u00a0connect to a wide variety of databases including MySQL, Oracle, Mongo and even IBM DB2. This","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-node-module-connects-db2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"Node.js","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/node-js\/"},{"@type":"ListItem","position":4,"name":"Building a Node Module That Connects to DB2"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b3add10a27821f3334ef6ea4517afa38","name":"Brian De Sousa","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e6d9ee737fde3578595268395d83bed5675158601972fb206794255c46798404?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e6d9ee737fde3578595268395d83bed5675158601972fb206794255c46798404?s=96&d=mm&r=g","caption":"Brian De Sousa"},"description":"Brian De Sousa is a senior software developer working in the financial industry. He has over 10 years of experience developing web applications with a variety of web technologies. He has a passion for developing solutions using the latest and greatest technologies and frameworks.","sameAs":["https:\/\/briandesousa1.wordpress.com\/","https:\/\/www.linkedin.com\/in\/briandesousa?trk=hp-identity-name","https:\/\/x.com\/briandesousa1"],"url":"https:\/\/www.webcodegeeks.com\/author\/brian-de-sousa\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/15926","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/141"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=15926"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/15926\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/924"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=15926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=15926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=15926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}