SAP HANA Database Client for Node.js (hdb)

2.27.1 · maintenance · verified Sun Apr 19

The `hdb` package provides a pure JavaScript client for connecting to SAP HANA Cloud and SAP HANA Platform servers from Node.js applications. Currently at stable version 2.27.1, the library typically sees patch releases addressing bug fixes, dependency updates, and minor feature enhancements. While `hdb` is fully supported by SAP for existing projects, for new development, SAP strongly encourages the use of the `@sap/hana-client` driver, which offers a more comprehensive feature set including automatic reconnect, connection pooling, and client-side data encryption, features explicitly marked as absent in `hdb`. This differentiation positions `hdb` as a viable client for established applications but a less feature-rich option compared to its C++ based counterpart for new projects.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates establishing an encrypted connection to SAP HANA, executing a simple SQL query, and handling errors and connection closure using environment variables for credentials.

import hdb from 'hdb';

const client = hdb.createConnection({
  host: process.env.HANA_HOST ?? 'localhost',
  port: parseInt(process.env.HANA_PORT ?? '30015', 10),
  user: process.env.HANA_USER ?? 'DBADMIN',
  password: process.env.HANA_PASSWORD ?? 'password',
  encrypt: true, // Use TLS encryption
  sslValidateCertificate: true // Validate server certificate
});

client.on('error', (err) => {
  console.error('SAP HANA Client Network Error:', err);
  client.end(); // Ensure connection is closed on error
});

client.connect((err) => {
  if (err) {
    return console.error('SAP HANA Connection Error:', err);
  }
  console.log('Connected to SAP HANA.');

  const sql = 'SELECT CURRENT_USER, CURRENT_SCHEMA FROM DUMMY;';
  client.exec(sql, (execErr, rows) => {
    if (execErr) {
      console.error('SAP HANA Query Execution Error:', execErr);
    } else {
      console.log('Query result:', rows);
      console.log('Current User:', rows[0].CURRENT_USER);
      console.log('Current Schema:', rows[0].CURRENT_SCHEMA);
    }
    client.end(); // Always close the connection
    console.log('Connection to SAP HANA closed.');
  });
});

view raw JSON →