Officially out now: The TypeDB 3.0 Roadmap

Node.js driver

The Node.js driver was developed by the TypeDB team to enable TypeDB support for Node.js software and developers.

The GitHub repository with the driver’s source code and release notes.

The default package manager’s page about the driver’s package.

Install

See the Version Compatibility table to check what versions of TypeDB and Node.js driver are compatible.

To install TypeDB Node.js driver:

npm install typedb-driver
See the command for older versions (<2.24.0)
npm install typedb-client

Quickstart

See below a short example of Node.js code that connects to a local TypeDB Core, creates a database named access-management-db, defines a schema, inserts some data, and then reads it.

const { TypeDB } = require("typedb-driver/TypeDB");
const { SessionType } = require("typedb-driver/api/connection/TypeDBSession");
const { TransactionType } = require("typedb-driver/api/connection/TypeDBTransaction");

async function main() {
    const DB_NAME = "access-management-db";
    const SERVER_ADDR = "127.0.0.1:1729";
    const driver = await TypeDB.coreDriver(SERVER_ADDR);
    if (await driver.databases.contains(DB_NAME)) {
        await driver.databases.get(DB_NAME).then(db => db.delete());
    }
    await driver.databases.create(DB_NAME);
    try {
        session = await driver.session(DB_NAME, SessionType.SCHEMA);
        try {
            transaction = await session.transaction(TransactionType.WRITE);
            await transaction.query.define("define person sub entity;");
            await transaction.query.define("define name sub attribute, value string; person owns name;");
            await transaction.commit();
        } finally {if (transaction.isOpen()) {await transaction.close()};}
    } finally {await session?.close();}
    try {
        session = await driver.session(DB_NAME, SessionType.DATA);
        try {
            transaction = await session.transaction(TransactionType.WRITE);
            await transaction.query.insert("insert $p isa person, has name 'Alice';");
            await transaction.query.insert("insert $p isa person, has name 'Bob';");
            await transaction.commit();
        } finally {if (transaction.isOpen()) {await transaction.close()};}
        try {
            transaction = await session.transaction(TransactionType.READ);
            await transaction.query.fetch("match $p isa person; fetch $p: name;").forEach(element => {
                console.log(JSON.stringify(element));
            });
        } finally {if (transaction.isOpen()) {await transaction.close()};}
    } finally {await session?.close();}
}
main();

For more code examples, see the Tutorial and API reference links below.

Learn more

This tutorial will help you learn how to use the Node.js driver.

Driver API reference for the Node.js language.

Any questions about the driver after reading the documentation? Feel free to ask on our Discord community server.

Version Compatibility

Node.js driver Protocol encoding version TypeDB Core TypeDB Cloud Node

2.28.0

3

2.28.0

2.28.0

>= 14.15

2.27.0

3

2.27.0

2.27.0

>= 14.15

2.26.6

3

2.26.6

2.26.6

>= 14.15

2.25.8

3

2.25.7

2.25.7

>= 14.15

2.24.15

2

2.24.17

2.24.17

>= 14.15

See older versions
Node.js driver Protocol encoding version TypeDB Core TypeDB Cloud Node

2.18.1, 2.18.2

1

2.18.0 to 2.23.0

2.18.0 to 2.23.0

>= 14.15

2.17.0

N/A

2.17.0

2.17.0

>= 14.15

2.16.1

N/A

2.16.1

2.16.1

>= 14.15

2.14.2

N/A

2.12.0 to 2.15.0

2.13.0 to 2.15.0

>= 14.15

2.9.0 to 2.11.1

N/A

2.9.0 to 2.11.1

2.9.0 to 2.11.2

>= 14.15

2.8.0

N/A

2.8.0

N/A

>= 14.15

2.6.0 to 2.6.2

N/A

2.6.0 to 2.7.1

N/A

>= 14.15

2.4.0 to 2.5.0

N/A

2.1.2 to 2.5.0

2.5.0

>= 14.15

2.1.0 to 2.2.0

N/A

2.1.2 to 2.5.0

2.1.2 to 2.3.0

>= 14.15

2.0.1

N/A

2.0.2

2.0.2

>= 14.15

2.0.0

N/A

2.0.0, 2.0.1

2.0.0, 2.0.1

>= 14.15

1.8.0

N/A

1.8.0 to 1.8.4

N/A

>= 6.5