{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"type":"markdown"},"seo":{"title":"Node.js Client for TD-API","description":"Learn how to use the Node.js client library for Treasure API. List databases and tables, issue Hive queries, and manage jobs programmatically.","siteUrl":"https://docs.treasuredata.com","lang":"en-US","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"nodejs-client-for-td-api","__idx":0},"children":["Node.js Client for TD-API"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This article will explain how to use Node.js bindings for REST API."]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"warning","name":"Beta Product"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This module is still under active development. Some REST API bindings have not been implemented yet."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"prerequisites","__idx":1},"children":["Prerequisites"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Basic knowledge of Treasure Data, including the"," ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://toolbelt.treasuredata.com/"},"children":["Toolbelt"]},"."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"setup","__idx":2},"children":["Setup"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The module is published in ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://www.npmjs.com/package/td"},"children":["NPM"]},". Add the following line to your ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["package.json"]}," file."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"json","header":{"controls":{"copy":{}}},"source":"\"td\": \">=0.2.7\"\n","lang":"json"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"basic-use","__idx":3},"children":["Basic Use"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"list-databases-and-tables","__idx":4},"children":["List Databases and Tables"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The example below prints out all your tables to the console."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"var TD = require('td');\nvar client = new TD('TREASURE_DATA_API_KEY');\n\nclient.listDatabases(function(err, results) {\n  var i;\n  var fnPrint = function(err, results) {\n    console.log(results);\n  };\n\n  if (err || !results.databases) {\n    return;\n  }\n\n  for (i = 0; i < results.databases.length; i++) {\n    client.listTables(results.databases[i].name, fnPrint);\n  }\n});\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"issue-queries","__idx":5},"children":["Issue Queries"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The example below issues a query from Node.js. After issuing the query,"," ","a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["job_id"]}," field is printed out. This can be used to query the results."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"var TD = require('td');\nvar client = new TD('TREASURE_DATA_API_KEY');\n\nclient.hiveQuery('testdb', \"SELECT code, COUNT(1) AS cnt FROM www_access GROUP BY code\", function(err, results) {\n  console.log(results);\n});\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"list-and-get-the-status-of-jobs","__idx":6},"children":["List and Get the Status of Jobs"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The example below lists and gets the status of jobs."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"var TD = require('td');\nvar client = new TD('TREASURE_DATA_API_KEY');\n\nvar fnPrint = function(err, results) {\n  console.log(results);\n};\n\n// list recent 20 jobs\nclient.listJobs(fnPrint);\n\n// recent 127 jobs of specific status\nclient.listJobs(0, 127, 'running', fnPrint);\nclient.listJobs(0, 127, 'success', fnPrint);\nclient.listJobs(0, 127, 'error', fnPrint);\n\n// get job status\nclient.showJob(job_id, fnPrint);\n\n// get job result\nclient.jobResult(job_id, fnPrint);\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"api-reference","__idx":7},"children":["API reference"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["For more details, refer to ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://treasure-data.github.io/td-client-node/docs/TDClient.html"},"children":["Treasure Data REST API Client"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"further-reading","__idx":8},"children":["Further Reading"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["The source code is on ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://github.com/treasure-data/td-client-node"},"children":["GitHub"]},"."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/data-workbench/queries/hive/quickstart"},"children":["Hive Query Engine"]}]}]}]},"headings":[{"value":"Node.js Client for TD-API","id":"nodejs-client-for-td-api","depth":1},{"value":"Prerequisites","id":"prerequisites","depth":2},{"value":"Setup","id":"setup","depth":2},{"value":"Basic Use","id":"basic-use","depth":2},{"value":"List Databases and Tables","id":"list-databases-and-tables","depth":3},{"value":"Issue Queries","id":"issue-queries","depth":3},{"value":"List and Get the Status of Jobs","id":"list-and-get-the-status-of-jobs","depth":3},{"value":"API reference","id":"api-reference","depth":2},{"value":"Further Reading","id":"further-reading","depth":2}],"frontmatter":{"seo":{"title":"Node.js Client for TD-API","description":"Learn how to use the Node.js client library for Treasure API. List databases and tables, issue Hive queries, and manage jobs programmatically."}},"lastModified":"2026-06-01T09:09:59.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/apis/td-api/td-client/td-client-node","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}