Difference between revisions of "Nodejs Integration"
Barrymavin (Talk | contribs) (→Module Methods) |
Barrymavin (Talk | contribs) (→Using the Lianja Cloud Data Services module in Node Applications) |
||
(13 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:Node.js Module}} | {{DISPLAYTITLE:Node.js Module}} | ||
− | + | Node.js is an open-source and cross-platform JavaScript runtime environment. | |
− | + | ||
− | Node.js is an open-source and cross-platform JavaScript runtime environment. | + | |
Node.js runs the V8 JavaScript engine, the core of Google Chrome, outside of the browser. This allows Node.js to be very performant. | Node.js runs the V8 JavaScript engine, the core of Google Chrome, outside of the browser. This allows Node.js to be very performant. | ||
Line 12: | Line 10: | ||
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. | 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== | + | ==Installing the Lianja Cloud Data Services Node module== |
The simplest way to use the Node.js module module is by creating a symbolic link using "npm link". | The simplest way to use the Node.js module module is by creating a symbolic link using "npm link". | ||
Line 29: | Line 27: | ||
Testing the installation: | Testing the installation: | ||
− | On | + | On Windows: |
− | <code lang='bash'> | + | <code lang='bash'> |
− | + | ||
cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\node\lianjaclouddataservices\ | cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\node\lianjaclouddataservices\ | ||
node test.js</code> | node test.js</code> | ||
− | + | On Linux: | |
− | <code lang='bash'> | + | <code lang='bash'> |
− | + | cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/node/lianjaclouddataservices/ | |
− | cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/node/lianjaclouddataservices | + | |
node test.js</code> | node test.js</code> | ||
+ | |||
+ | On MacOS: | ||
+ | |||
+ | <code lang='bash'> | ||
+ | cd /Users/shared/Lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/node/lianjaclouddataservices | ||
+ | node test.js | ||
+ | </code> | ||
==Using the Lianja Cloud Data Services module in Node Applications== | ==Using the Lianja Cloud Data Services module in Node Applications== | ||
Line 52: | Line 55: | ||
See [[OData_URIs|OData URIs]] for details of OData URIs and [[OData_Operators|OData Operators]] for all the OData operators. | See [[OData_URIs|OData URIs]] for details of OData URIs and [[OData_Operators|OData Operators]] for all the OData operators. | ||
+ | |||
+ | You can use also use the Lianja Key-Value Store (Lianja/KVS) with Node.js. See [[Key-Value_Store|Lianja/KVS]] for details. | ||
==Module Methods== | ==Module Methods== | ||
Line 59: | Line 64: | ||
|- | |- | ||
|valign="top"|Lianja.login(host, user, password) | |valign="top"|Lianja.login(host, user, password) | ||
− | |valign="top"|Login to a local or remote Cloud Server. | + | |valign="top"|Login and connect to to a local or remote Cloud Server. To connect locally specify the host as http: //localhost:8001 |
|- | |- | ||
|valign="top"|Lianja.logout() | |valign="top"|Lianja.logout() | ||
− | |valign="top"| | + | |valign="top"|Logout from the local or remote Cloud Server. |
|- | |- | ||
|valign="top"|Lianja.evaluate(expr) | |valign="top"|Lianja.evaluate(expr) | ||
Line 72: | Line 77: | ||
|valign="top"|Lianja.evaluateJavaScript(expr) | |valign="top"|Lianja.evaluateJavaScript(expr) | ||
|valign="top"|Evaluates JavaScript expression and returns the result asynchronously. | |valign="top"|Evaluates JavaScript expression and returns the result asynchronously. | ||
+ | |- | ||
+ | |valign="top"|Lianja.fetch(url) | ||
+ | |valign="top"|Fetches data from the server using an .rsp, .pysp or .jssp server side page. Use fetch() to retrieve custom data from the server. | ||
|- | |- | ||
|valign="top"|Lianja.OData_Create(url, data) | |valign="top"|Lianja.OData_Create(url, data) | ||
Line 102: | Line 110: | ||
|} | |} | ||
− | + | <code lang='javascript'> | |
+ | // | ||
+ | // Lianja Node.js module test | ||
+ | // | ||
+ | // On windows: | ||
+ | // | ||
+ | // cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\node\ | ||
+ | // npm link | ||
+ | // cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\node\lianjaclouddataservices\ | ||
+ | // node test.js | ||
+ | // | ||
+ | // on Linux: | ||
+ | // | ||
+ | // cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/node/ | ||
+ | // npm link | ||
+ | // cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/node/lianjaclouddataservices/ | ||
+ | // node test.js | ||
+ | // | ||
+ | // on MacOS: | ||
+ | // | ||
+ | // cd /Users/shared/Lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/node/lianjaclouddataservices/ | ||
+ | // node test.js | ||
+ | // | ||
− | + | const Lianja = require("lianjaclouddataservices"); | |
− | + | // All Lianja methods are asynchronous as required by Node.js | |
+ | |||
+ | var rc = Lianja.login("admin", "admin").then(ok => | ||
{ | { | ||
− | + | console.log("Lianja.login() - " + (ok ? "successful" : "failed")); | |
− | + | if (ok) performOperations() | |
− | }); | + | }); |
− | + | function performOperations() | |
− | + | { | |
+ | Lianja.evaluate("username()").then(result => | ||
+ | { | ||
+ | console.log("username - " + result); | ||
+ | }); | ||
+ | |||
+ | Lianja.evaluate("etos(date()) + ' ' + time()").then(result => | ||
+ | { | ||
+ | console.log("Lianja.evaluate() - " + result); | ||
+ | }); | ||
− | + | Lianja.OData_Read("/southwind/employees?$top=1").then(result => | |
− | + | { | |
− | + | console.log("Lianja.OData_Read()"); | |
− | + | console.log(result); | |
− | + | }); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | Lianja.OData_ReadHTML("/southwind/employees?$select=notes&$filter=lastname eq 'Buchanan'").then(result => | |
− | { | + | { |
− | + | console.log("Lianja.OData_ReadHTML()"); | |
− | + | console.log(result); | |
− | }); | + | }); |
− | + | Lianja.OData_ReadImage("/southwind/employees?$select=photo&$filter=lastname eq 'Buchanan'").then(result => | |
− | + | { | |
− | + | console.log("Lianja.OData_ReadImage()"); | |
− | + | console.log("size="+result.length); | |
− | { | + | }); |
− | + | }; | |
− | });</code> | + | </code> |
[[Category:Lianja Server]] | [[Category:Lianja Server]] | ||
[[Category:Lianja v9.6]] | [[Category:Lianja v9.6]] | ||
[[Category:OData Functions|* Node.js]] | [[Category:OData Functions|* Node.js]] |
Latest revision as of 21:48, 30 May 2024
Node.js is an open-source and cross-platform JavaScript runtime environment.
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.
Contents
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 Node 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
Testing the installation:
On Windows:
cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\node\lianjaclouddataservices\
node test.js
On Linux:
cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/node/lianjaclouddataservices/ node test.js
On MacOS:
cd /Users/shared/Lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/node/lianjaclouddataservices node test.js
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).
See OData URIs for details of OData URIs and OData Operators for all the OData operators.
You can use also use the Lianja Key-Value Store (Lianja/KVS) with Node.js. See Lianja/KVS for details.
Module Methods
Function | Description |
---|---|
Lianja.login(host, user, password) | Login and connect to to a local or remote Cloud Server. To connect locally specify the host as http: //localhost:8001 |
Lianja.logout() | Logout from the local or remote Cloud Server. |
Lianja.evaluate(expr) | Evaluates LianjaScript expression and returns the result asynchronously. |
Lianja.evaluatePython(expr) | Evaluates Python expression and returns the result asynchronously. |
Lianja.evaluateJavaScript(expr) | Evaluates JavaScript expression and returns the result asynchronously. |
Lianja.fetch(url) | Fetches data from the server using an .rsp, .pysp or .jssp server side page. Use fetch() to retrieve custom data from the server. |
Lianja.OData_Create(url, data) | See ODATA_CREATE() |
Lianja.OData_Read(url) | See ODATA_READ() |
Lianja.OData_ReadHTML(url) | See See ODATA_READ() |
Lianja.OData_ReadJSON(url) | See See ODATA_READ() |
Lianja.OData_ReadImage(url) | See See ODATA_READ() |
Lianja.OData_Update(url, data) | See ODATA_UPDATE() |
Lianja.OData_UpdateHTML(url, text) | See ODATA_UPDATE() |
Lianja.OData_UpdateJSON(url, jsontext) | |
Lianja.OData_Delete(url, data) | See ODATA_DELETE() |
// // Lianja Node.js module test // // On windows: // // cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\node\ // npm link // cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\node\lianjaclouddataservices\ // node test.js // // on Linux: // // cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/node/ // npm link // cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/node/lianjaclouddataservices/ // node test.js // // on MacOS: // // cd /Users/shared/Lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/node/lianjaclouddataservices/ // node test.js // const Lianja = require("lianjaclouddataservices"); // All Lianja methods are asynchronous as required by Node.js var rc = Lianja.login("admin", "admin").then(ok => { console.log("Lianja.login() - " + (ok ? "successful" : "failed")); if (ok) performOperations() }); function performOperations() { Lianja.evaluate("username()").then(result => { console.log("username - " + result); }); Lianja.evaluate("etos(date()) + ' ' + time()").then(result => { console.log("Lianja.evaluate() - " + result); }); Lianja.OData_Read("/southwind/employees?$top=1").then(result => { console.log("Lianja.OData_Read()"); console.log(result); }); Lianja.OData_ReadHTML("/southwind/employees?$select=notes&$filter=lastname eq 'Buchanan'").then(result => { console.log("Lianja.OData_ReadHTML()"); console.log(result); }); Lianja.OData_ReadImage("/southwind/employees?$select=photo&$filter=lastname eq 'Buchanan'").then(result => { console.log("Lianja.OData_ReadImage()"); console.log("size="+result.length); }); };