STEP1: Creating Node.js File and save it as gumu.js
Writing Node.js code with build in modules and user defined modules and save it on Root Drive:\Sage\SyracuseComponent\syracuse\bin\node_modules\bundles\ greytrix\lib\gumu.js
Create the folder under bundles(greytrix\lib)
Fig 1.1-Code Description:
The “use strict” Directive:
To make Node.js act as an HTTP server include the module. Include the module using require() function with the name of the module.
Server:var http = require(‘http’);
Application has access to the HTTP module, and is able to create a server.
Node.js has a built-in module called HTTP, which allows Node.js to transfer data over the Hyper Text Transfer Protocol (HTTP).
To identity the httpclient we can declare
Client : var httpClient = require(‘syracuse-httpclient/lib/httpClient’);
Create user defined Modules:
Use the exports keyword to make properties and methods available outside the module file.
STEP2: Passing argument from x3 client
Fig 2.1-Code Description:
The function EXEC_JS is located in the ASYRWEBSER library and func ASYRWEBSER.EXEC_JS is used to execute node.js file and its definition is the following
- A mode to determine if the call is synchronous or asynchronous (‘sync’ or ‘wait’).
- Multiple arguments delimited by ‘,’ ; It can be JSON format or every types.
- Specify if arguments must be base64 encoded or not. A list of ‘0’ or ‘1’ separated by ‘,’.
- Can be empty if no base64 encoding is needed for any argument.
- Important: when it is not an empty string, it must match exactly the number of arguments.
- Base 64_IN.
- Specify the location of callback function. This is needed only for ‘wait’ mode.
- The value depends on the function.
- -1 is the value to say that the callback location is the last parameter.
- Used to filter JSON Objects .
- Specify the needs to encode the response to base64 or not. Can be ‘0’ or ‘1’
- Base 64_OUT
- The http response header.
- The Response body. The response will be stored in this variable.
STEP 3: Output
Note: Restart the Sage Syracuse – NODE0 service when changes done on gumu.js file
This blog helps us to understand how to write encode function on node.js server by passing input parameter from X3 client.