All Products
Search
Document Center

Tablestore:Node.js SDK

Last Updated:Jun 10, 2026

Use Tablestore SDK for Node.js to perform wide column model operations.

Quick start

Set up the environment, install the SDK, and initialize the client.

Prerequisites

  • Node.js 4.0 or later.

    Important

    Do not use Node.js 12.0 to 12.14 due to compatibility issues.

  • A Node.js development tool.

Install the SDK

Run the following command to install the SDK:

npm install tablestore

Sample programs for common wide column model operations:

Configure access credentials

Create an AccessKey for your Alibaba Cloud account or RAM user, then configure it as an environment variable to avoid hard-coding credentials.

Restart your IDE, terminal, other desktop applications, and background services after configuration to load the updated environment variables. For more information about other types of access credentials, see Configure access credentials.

Linux

  1. Append the environment variables to ~/.bashrc:

    echo "export TABLESTORE_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.bashrc
    echo "export TABLESTORE_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.bashrc
  2. Apply the changes:

    source ~/.bashrc
  3. Verify the environment variables:

    echo $TABLESTORE_ACCESS_KEY_ID
    echo $TABLESTORE_ACCESS_KEY_SECRET

macOS

  1. Check your default shell:

    echo $SHELL
  2. Configure based on your shell type:

    Zsh
    1. Append the environment variables to ~/.zshrc:

      echo "export TABLESTORE_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.zshrc
      echo "export TABLESTORE_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.zshrc
    2. Apply the changes:

      source ~/.zshrc
    3. Verify the environment variables:

      echo $TABLESTORE_ACCESS_KEY_ID
      echo $TABLESTORE_ACCESS_KEY_SECRET
    Bash
    1. Append the environment variables to ~/.bash_profile:

      echo "export TABLESTORE_ACCESS_KEY_ID='YOUR_ACCESS_KEY_ID'" >> ~/.bash_profile
      echo "export TABLESTORE_ACCESS_KEY_SECRET='YOUR_ACCESS_KEY_SECRET'" >> ~/.bash_profile
    2. Apply the changes:

      source ~/.bash_profile
    3. Verify the environment variables:

      echo $TABLESTORE_ACCESS_KEY_ID
      echo $TABLESTORE_ACCESS_KEY_SECRET

Windows

CMD
  1. Set the environment variables in CMD:

    setx TABLESTORE_ACCESS_KEY_ID "YOUR_ACCESS_KEY_ID"
    setx TABLESTORE_ACCESS_KEY_SECRET "YOUR_ACCESS_KEY_SECRET"
  2. Restart CMD and verify:

    echo %TABLESTORE_ACCESS_KEY_ID%
    echo %TABLESTORE_ACCESS_KEY_SECRET%
PowerShell
  1. Run in PowerShell:

    [Environment]::SetEnvironmentVariable("TABLESTORE_ACCESS_KEY_ID", "YOUR_ACCESS_KEY_ID", [EnvironmentVariableTarget]::User)
    [Environment]::SetEnvironmentVariable("TABLESTORE_ACCESS_KEY_SECRET", "YOUR_ACCESS_KEY_SECRET", [EnvironmentVariableTarget]::User)
  2. Verify the environment variables:

    [Environment]::GetEnvironmentVariable("TABLESTORE_ACCESS_KEY_ID", [EnvironmentVariableTarget]::User)
    [Environment]::GetEnvironmentVariable("TABLESTORE_ACCESS_KEY_SECRET", [EnvironmentVariableTarget]::User)

Initialize the client

Initialize the client and list tables to verify the connection.

Important

Public network access is disabled by default for new instances. To use public network access, enable it in the Network Management.

var TableStore = require('tablestore');

// Replace yourInstanceName with your instance name
var instancename = 'yourInstanceName';
// Replace yourEndpoint with your instance endpoint
var endpoint = 'yourEndpoint';
// Obtain the AccessKey ID and AccessKey Secret from environment variables
var accessKeyId = process.env.TABLESTORE_ACCESS_KEY_ID;
var secretAccessKey = process.env.TABLESTORE_ACCESS_KEY_SECRET;

// Initialize the Tablestore client
var client = new TableStore.Client({
  accessKeyId: accessKeyId,
  secretAccessKey: secretAccessKey,
  endpoint: endpoint,
  instancename: instancename
});

// List all tables in the instance and print to the console
client.listTable({}, function (err, data) {
    if (err) {
        console.log('error:', err);
        return;
    }
    console.log('success:', data);
});

Data types

Tablestore data types map to Node.js SDK types as follows.

Tablestore data type

Node.js SDK data type

Description

String

string

A JavaScript primitive type.

Integer

int64

JavaScript lacks a native 64-bit integer type. The SDK provides int64 through TableStore.Long.

Double

number

A JavaScript primitive type.

Boolean

boolean

A JavaScript primitive type.

Binary

Buffer

A Node.js Buffer object for handling binary data.

TableStore.Long converts between int64 and JavaScript number or string types:

// Construct int64 from number or string
const valueA = TableStore.Long.fromNumber(1000);
const valueB = TableStore.Long.fromString('2000');

// Convert int64 back to native JavaScript types
const numA = valueA.toNumber();   // 1000
const strA = valueA.toString();   // '1000'

const numB = valueB.toNumber();   // 2000
const strB = valueB.toString();   // '2000'

FAQ

References

For information about error handling in Tablestore, see Error handling.