Running a Node.js Application
After installing the driver, you will need an IP of the cluster and user credentials. These will be used in the same way as with other databases.
In the following example, you’ll find code that performs operations similar to those described in the Regatta Platform section.
To begin, import the relevant methods using the ‘node-regatta’require statement:
Please ensure that you import all relevant classes and methods based on your application’s functionality and requirements. Next, add the IP address and credentials obtained earlier (see External Access to the Regatta Database):
Any code that performs SQL commands should be updated accordingly.
To help you get acquainted with the Regatta API for Node.js, we’ve provided a simple code example below. Additionally, a more comprehensive example is included in the driver package under examples/node_regatta_examples.js. These documented examples demonstrate common tasks such as creating connections, executing queries, and working with cursors. The Regatta API supports both promise-based and callback-based semantics.
Unlike the Regatta Platform, in the commands used by the driver we need to specify the device mapping when creating a table. In the example below we will use a single device.
Below is an example of some of the code.
Note that a more robust example is also available as part of the downloaded driver.
Figure 51 Node.js example of application using driver
Following is the output of the application:
Figure 52 Node.js example output
Note that all commands performed in the Regatta Platform section can be performed in the same manner using a Node.js driver.