Difference between revisions of "Nodejs Integration"

From Lianjapedia
Jump to: navigation, search
(Installing the Lianja Cloud Data Services module)
(Using the Lianja Cloud Data Services module in Node Applications)
Line 29: Line 29:
 
==Using the Lianja Cloud Data Services module in Node Applications==
 
==Using the Lianja Cloud Data Services module in Node Applications==
  
 +
Load the module into your Node.js application
 +
 +
<code lang='javascript'>const Lianja = require("Lianjaclouddataservices")</code>
 +
 +
Exported functions. All are asynchronous returning a "Promise" (see example usage below).
 +
 +
Lianja.login(host, user, password)
 +
 +
Lianja.logout()
 +
 +
Lianja.evaluate(expr)
 +
 +
Lianja.evaluatePython(expr)
 +
 +
Lianja.evaluateJavaScript(expr)
 +
 +
Lianja.OData_Create(url, data)
 +
 +
Lianja.OData_Read(url)
 +
 +
Lianja.OData_ReadHTML(url)
 +
 +
Lianja.OData_ReadJSON(url)
 +
 +
Lianja.OData_ReadImage(url)
 +
 +
Lianja.OData_Update(url, data)
 +
 +
Lianja.OData_UpdateHTML(url, data)
 +
 +
Lianja.OData_UpdateJSON(url, data)
 +
 +
Lianja.OData_Delete(url, data)
 +
 +
Example usage:
 +
 +
Login into the Cloud Server (can be local or remote). Use https:// if remote using SSL.
 +
 +
<code lang='javascript'>Lianja.login("http:localhost:8001", "someuser", "somepassword").then(ok =>
 +
{
 +
    console.log("Lianja.login() - " + (ok ? "successful" : "failed"));
 +
    if (ok) performOperations()
 +
});</code>
 +
 +
Read some data. This is returned in JSON format. The data returned can be accessed by result.d.results. This is an array of JSON objects.
 +
Other metadata can also be accessed using:
 +
 +
result.d.results - The result as an array of objects
 +
result.d.__count - This is the total number of records in the table
 +
result.d.__reccount - This is the total number of rows returned
 +
 +
<code lang='javascript'>Lianja.OData_Read("/southwind/employees?$top=1").then(result =>
 +
{
 +
    console.log("Lianja.OData_Read()");
 +
    console.log(result);
 +
});</code>
 +
 +
Remote evaluation of expressions and procs().
 +
Use mylib::myproc() to reference procs in libraries on the server
 +
 +
<code lang='javascript'>Lianja.evaluate("etos(date()) + ' ' + time()").then(result =>
 +
{
 +
    console.log("Lianja.evaluate() - " + result);
 +
});</code>
  
 
[[Category:Lianja Server]]
 
[[Category:Lianja Server]]

Revision as of 04:09, 22 April 2024

**Under Development**

Node.js is an open-source and cross-platform JavaScript runtime environment. It is a popular tool for almost any kind of project!

Node.js runs the V8 JavaScript engine, the core of Google Chrome, outside of the browser. This allows Node.js to be very performant.

A Node.js app runs in a single process, without creating a new thread for every request. Node.js provides a set of asynchronous I/O primitives in its standard library that prevent JavaScript code from blocking and generally, libraries in Node.js are written using non-blocking paradigms, making blocking behavior the exception rather than the norm.

Lianja Cloud Data Services Node module

Lianja Cloud Server includes a Node.js module lianjaclouddataservices enabling Node.js applications to connect to a local or remote Lianja Cloud Server and perform a variety of operations.

Installing the Lianja Cloud Data Services module

The simplest way to use the Node.js module module is by creating a symbolic link using "npm link".

On Windows:

cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\node\
npm link

On Linux:

cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/node/
npm link

Using the Lianja Cloud Data Services module in Node Applications

Load the module into your Node.js application

const Lianja = require("Lianjaclouddataservices")

Exported functions. All are asynchronous returning a "Promise" (see example usage below).

Lianja.login(host, user, password)

Lianja.logout()

Lianja.evaluate(expr)

Lianja.evaluatePython(expr)

Lianja.evaluateJavaScript(expr)

Lianja.OData_Create(url, data)

Lianja.OData_Read(url)

Lianja.OData_ReadHTML(url)

Lianja.OData_ReadJSON(url)

Lianja.OData_ReadImage(url)

Lianja.OData_Update(url, data)

Lianja.OData_UpdateHTML(url, data)

Lianja.OData_UpdateJSON(url, data)

Lianja.OData_Delete(url, data)

Example usage:

Login into the Cloud Server (can be local or remote). Use https:// if remote using SSL.

Lianja.login("http:localhost:8001", "someuser", "somepassword").then(ok =>
{
    console.log("Lianja.login() - " + (ok ? "successful" : "failed"));
    if (ok) performOperations()
});

Read some data. This is returned in JSON format. The data returned can be accessed by result.d.results. This is an array of JSON objects. Other metadata can also be accessed using:

result.d.results - The result as an array of objects result.d.__count - This is the total number of records in the table result.d.__reccount - This is the total number of rows returned

Lianja.OData_Read("/southwind/employees?$top=1").then(result => 
{
    console.log("Lianja.OData_Read()");
    console.log(result);	
});

Remote evaluation of expressions and procs(). Use mylib::myproc() to reference procs in libraries on the server

Lianja.evaluate("etos(date()) + ' ' + time()").then(result => 
{
    console.log("Lianja.evaluate() - " + result);
});