Node.js / JavaScript
|
Connection options for Node.js / JavaScript ArcadeDB exposes multiple wire protocols, so you can pick the one your stack already speaks:
This page covers the PostgreSQL and HTTP/JSON approaches in detail. A BOLT example is coming soon. |
ArcadeDB can be accessed from Node.js in three ways:
| Method | Best For | Library |
|---|---|---|
Neo4j BOLT |
Cypher / graph workloads |
|
PostgreSQL protocol |
Most applications |
|
HTTP/JSON API |
Lightweight scripts, serverless, browsers |
|
PostgreSQL Protocol (Recommended)
ArcadeDB speaks the PostgreSQL wire protocol natively. Use the standard pg client.
npm install pg
const { Client } = require('pg');
const client = new Client({
host: 'localhost',
port: 5432,
database: 'mydb',
user: 'root',
password: 'arcadedb',
});
await client.connect();
// SQL queries
const result = await client.query('SELECT FROM V LIMIT 10');
console.log(result.rows);
// Cypher queries (prefix with {cypher})
const cypher = await client.query('{cypher} MATCH (n) RETURN n LIMIT 10');
console.log(cypher.rows);
// Graph traversal with MATCH
const graph = await client.query(`
SELECT person.name, friend.name
FROM MATCH {type: Person, as: person}
-Knows-> {type: Person, as: friend}
`);
for (const row of graph.rows) {
console.log(`${row['person.name']} knows ${row['friend.name']}`);
}
await client.end();
HTTP/JSON API
For lightweight scripts, serverless functions, or browser-side code:
Using fetch (Node.js 18+ or browsers)
const base = 'http://localhost:2480/api/v1';
const auth = 'Basic ' + btoa('root:arcadedb');
const response = await fetch(`${base}/command/mydb`, {
method: 'POST',
headers: {
'Authorization': auth,
'Content-Type': 'application/json',
},
body: JSON.stringify({
language: 'sql',
command: 'SELECT FROM V LIMIT 10',
}),
});
const data = await response.json();
console.log(data);
Using axios
npm install axios
const axios = require('axios');
const auth = 'Basic ' + btoa('root:arcadedb');
const res = await axios.post(
'http://localhost:2480/api/v1/command/mydb',
{ language: 'sql', command: 'SELECT FROM V LIMIT 10' },
{ headers: { 'Authorization': auth, 'Content-Type': 'application/json' } },
);
console.log(res.data);
TypeScript
Both pg and fetch work with TypeScript. Install type definitions for pg:
npm install pg @types/pg
import { Client } from 'pg';
const client = new Client({
host: 'localhost',
port: 5432,
database: 'mydb',
user: 'root',
password: 'arcadedb',
});
await client.connect();
const result = await client.query('SELECT FROM V LIMIT 10');
console.log(result.rows);
await client.end();
Further Reading
-
JavaScript Quickstart Tutorial — Step-by-step tutorial
-
Supply Chain Use Case — Full JavaScript implementation with 7 query patterns