Node.js
Full API docs can be found on the client SDK project page, but the basics are summarized here.
Using Db2 for IBM i with Node.js is easy. First, install the package:
Basic architecture
mapepire-js is a pooling asynchronous client to an instance of the mapepire-server. The mapepire-server authorizes and mediates connections to an IBM i Db2 server on behalf of the client.
This document illustrates the use of the mapepire-js client. Other language clients and the mapepire-server itself are documented elsewhere.
Simple test
Credentials belong in an object which can be passed to a Pool
or SQLJob
.
Create a function to test the database connection and run it:
Pooling
For typical production workloads, a connection pool should be used and created when in your apps startup process.
The pool provides APIs to access a free job or to send a query directly to a free job.
Securing
By default, Mapepire will always try to connect securely. A majority of the time, servers are using their own self-signed certificate that is not signed by a recognized CA (Certificate Authority). There are two options with the Node.js client:
Allow all certificates
On the DaemonServer
interface, the ignoreUnauthorized
set to true
will allow either self-signed certificates or certificates from a CA.
Validate the self-signed certificate
The Mapepire Node.js client ships with an API, getCertificate
, where you can fetch the self-signed certificate from the server before connecting to the Mapepire daemon. This allows your code to validate it using your own validation implementation before using it.
getCertificate
returns an object with the raw
property, which can in turn be passed in as ca
as part of the DaemonServer
interface.