UltipaDocs
Try Playground
  • Introduction
  • RESTful API
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
  1. Docs
  2. /
  3. Ultipa Drivers
  4. /
  5. Node.js

Connection

After installing the Ultipa Node.js SDK and setting up a running Ultipa instance, you should be able to connect your application to the Ultipa graph database.

ConnectionPool

Connection to Ultipa can be established by using ConnectionPool, which specifies the information of the connection pool needed.

Below are all the configuration items available for ConnectionPool:

Item
Type
Description
hostsstring[]Database host addresses or host URI (excluding "https://" or "http://"). For clusters, multiple addresses are seperated by commas. Required.
usernamestringUsername of the host authentication. Required.
passwordstringPassword of the host authentication. Required.
crtBufferSets the local certificate file path. SSL will be used for connection.
defaultConfigULTIPA.UltipaConfigOther configurations include settings for the graphset, timeout, and consistency.
otherParamsobjectTwo keys are available: isHttps and isHttp, both as boolean values. If both are set to true, HTTP is used first. If not specified, the connection tries HTTP first, and switches to HTTPS if HTTP fails.

Connect to a Cluster

Example of connecting to a cluster and using graphset 'default'.

TypeScript
import { ConnectionPool } from "@ultipa-graph/ultipa-node-sdk";
import fs from "fs";

let sdkUsage = async () => {

  let hosts = [
    "192.168.1.85:60061", 
    "192.168.1.86:60061", 
    "192.168.1.87:60061"
  ];
  let username = "***";
  let password = "***";
  let crt: Buffer;
  { // Crt is used
    let crt_file_path = "./ultipa.crt";
    crt = fs.readFileSync(crt_file_path);
  }
  let connPool = new ConnectionPool(hosts, username, password, crt);
  
  let conn = await connPool.getActive();
  let isSuccess = await conn.test();
  console.log(isSuccess);
};

sdkUsage().then(console.log).catch(console.log);

Connect to Ultipa Cloud

Example of connecting to an instance on Ultipa Cloud and using graphset 'default'.

TypeScript
import { ConnectionPool } from "@ultipa-graph/ultipa-node-sdk";

let sdkUsage = async () => {

  let hosts = ["3xbotdjas.us-east-1.cloud.ultipa.com:60010"];
  let username = "***";
  let password = "***";
  let otherParams = {
    isHttps: true,
    isHttp: false
  };
  let connPool = new ConnectionPool(hosts, username, password, undefined, undefined, otherParams);
  
  let conn = await connPool.getActive();
  let isSuccess = await conn.test();
  console.log(isSuccess);
};

sdkUsage().then(console.log).catch(console.log);

Configuration Items

Below are all the configuration items available for UltipaConfig:

Item
Type
Description
graphSetNamestringName of the graph to use. If not set, use the graphSetName configured when establishing the connection.
timeoutnumberRequest timeout threshold in seconds.
consistencybooleanWhether to use the leader node to ensure consistency read.
useHoststringSends the request to a designated host node, or to a random host node if not set.
clusterIDstringSpecifies the cluster to use.
timeZonestringThe time zone to use.
timeZoneOffsetnumberThe amount of time that the time zone in use differs from UTC in minutes.
timestampToStringbooleanWhether to convert timestamp to string.
logUqlbooleanWhether to print the UQL.
threadNumnumberNumber of threads.
responseWithRequestInfobooleanWhether to include request information in the response.