Node Services


Node services can be called from Node modules, other Node services and Xbasic scripts.


Node services can be created and managed from within Alpha Anywhere. The Node services category in the Web Projects Control Panel will filter the project to display node services in the project. A Node service can be created using the New toolbar button. Node services can also be added from the Node menu in the More... options on the Web Projects Control Panel toolbar.

Node Services can reference Node Modules in their implementation. Because Node Services can be called from Xbasic, this allows you to extend the capabilities of Xbasic using server-side JavaScript and Node Modules available through the extensive NMP (Node Packet Manager) library and any custom Node Modules you have created.

 Creating a New Node Service

When the Node category in the Web Projects Control Panel is selected, the New button will prompt you to create a new Node Service, Node Module, or Node API. If you create a new Node Service, Alpha Anywhere will create a new stub Node service that serves as a helpful starting point for defining a new service.

  1. Select the Node category in the Web Projects Control Panel.

  2. Click the New button in the Web Projects Control Panel toolbar.

  3. Select Create a new Node Service Javascript file from the New Node Javascript File dialog:

  4. In the Create Node Service Stub dialog, enter a Service name. Optionally check (or uncheck) the Open service definition .js file after creating it? checkbox. Click OK.

  5. Alpha Anywhere will generate a Node Service stub. The stub includes comments that describe how to call the Node Service from Xbasic.

    Create your Node service. Save your changes.

 Calling a Node Service from Xbasic

Once you have defined your Node service, you can call it from your Xbasic code using the node_request_result() function.

For example, say you have define a service called multiply and that this service takes as input x and y. Here is how you could call the service from Xbasic:

dim pIn as p
pIn.x = 4
pIn.y = 3

dim pOut as p
pOut = node_request_result("multiply",pIn)

? pOut.error
= ""  'empty string indicates no errors.

= 12