Quark Engine for NodeJS

If you are familiar with IBM i, then you are aware about DDM services and for what it is used for. You don't? If we say JT400, it might ring a bell. As far as we know, there are 2 libraries allowing you to use DDM services - JT400 for Java and C/C++ native libs.

JT400 is very powerful and easy to understand and use, but somehow limiting to Java. If one wants to use it outside Java, only real solution is to expose JT400 functionalities as a kind of web service. Combined with Green Screens Quark Engine, this process is much easier, and now with Quark Engine for NodeJS integration is even easier.

So, the question is "What is Quark Engine for NodeJS?"

Quark Engine for NodeJS is an integration client library allowing NodeJS based apps to call remote Java Quark Engine based services in the same way it is possible with browser client library.

Quark Engine for NodeJS will generate dynamic API allowing you to call remote Java web controller methods in an API style instead of implementing your own WebSocket or HTTP/s calls and URI's.

All features are available as in the original browser version supporting data encryption and compression.

Here is a simple example how to initialize and use Quark Engine for NodeJS client library.

const QuarkEngine = require('quark');

const channelWeb = "http://localhost:8080/io.greenscreens.quark/api";
const channelWS = "ws://localhost:8080/io.greenscreens.quark/socket";

async function test1() {

    // in real life, initialize only once per service api through whole application
    let Engine = new QuarkEngine({api:channelWeb, service: channelWeb});

    // initialze engine
    await Engine.init();

    // get genrated API as local scoped variable
    // or attach it to global scope for all other modules
    // global.io = Engine.api.io
    const { io } = Engine.api;

    console.log(io);

    let o = await io.greenscreens.Demo.hello('John Doe');
    console.log(o);

    o = await io.greenscreens.Demo.listUsers();
    console.log(o);
    
    // optionally release resources
    Engine.stop();
}

test1();

An example using Quark Engine for NodeJS in other modules after the Engine is initialized.

// if io is attached to global

async function test1() {

    let o = await io.greenscreens.Demo.hello('John Doe');
    console.log(o);

    o = await io.greenscreens.Demo.listUsers();
    console.log(o);
}

test1();

// or with promise approach ...

io.greenscreens.Demo.hello('John Doe')
 .then(o => {
   console.log(o);
 })
 .catch(e => {
   console.log(e);
 });

As one can see, it is much cleaner and easier to write NodeJS code and to integrate with remote Java services. This is ideal for general use and specially for IBM i to utilize DDM services. As DDM services are only available in Java and C/C++, it becomes immediately clear why.

Creating Java Based Microservices utilizing JT400 and exposing them through Quark Engine makes it easy to implement direct calls through web browser or NodeJS.

NodeJS principle is to have many small memory efficient microservices for specific use, but similar is possible with Java MicroServices stack with which Green Screens Quark Engine is compatible. As both technologies are available on IBM i, but not limited to, it is an ideal combination of two complementary technologies.

Complete source and instructions can be found on our Github repository.

Source is under MIT license and freely available to everyone.