Artem Bykov Avatar

Artem Bykov

Artem is a passionate web developer that likes to stay current in cutting edge technologies. With great expertise, you can always expect clean and maintainable code from him. Before Zoomdata, Artem worked on several E-Commerce websites and gambling projects- He also worked for an online travel agency. In his free time, Artem enjoys football, skiing, and traveling. More recently, he has been getting trying to get better at snowboarding.

3 min read · December 6th 2017 (originally published at Medium)

Getting started with Zoomdata SDK in NodeJS

Blog Post Intro Image

We are going to write a simple Node.js application which connects to Zoomdata server and fetches data from some preconfigured source.

If you’re new to the Zoomdata SDK you can get an overview on the docs portal. In case you need more insights, there is a great post by Dmytro Gladkyi:

If you don’t want to go through the article, full source code is available on Github: artembykov/zoomdata-sdk-node

Let’s setup our project. We need to create a directory and move into it:

    $ mdkir zoomdata-sdk-node
    $ cd zoomdata-sdk-node

Next, we should create and fill up a package.json file:

$ npm init -y

Finally, we should install zoomdata-client dependency via

$ npm install zoomdata-client

After this, we can start writing our application code, which will live in the index.js file:

$ touch index.js

Assuming everything went well, we can start by requiring bundle for Node.js at the top of our script:

const ZoomdataSDK = require('zoomdata-client/distribute/sdk/zoomdata-client.node');

Next, we create a client with the necessary application configuration and credentials:

async function run() {
  const application = {
    secure: true,
    host: '',
    port: 443,
    path: '/zoomdata-2.6',

  const credentials = {
    key: 'KVKWiD8kUl',

  const client = await ZoomdataSDK.createClient({ application, credentials });

  console.log('Client ready');


Note that we wrap everything into async function run because the top-level await is not available in JavaScript.

If everything is ok, we can start querying data:

const queryConfig = {
    filters: [],
    groups: [{
        name: 'gender',
        limit: 10,
        sort: { dir: 'asc', name: 'gender' }
    metrics: [
        { name: 'satisfaction', func: 'sum' }

try {
    const data = await fetchData(client, 'My IMPALA Source', queryConfig);
    console.log('Received data:', data);
} finally {

In this piece, we try to fetch and log data from the source. If something goes wrong, the error will be passed through to outer catch. Regardless of the result we’re going to close a connection.

You may have noticed the fetchData function is not yet implemented. Well, let’s do it:

async function fetchData(client, name, queryConfig) {
  const query = await client.createQuery({ name }, queryConfig);

  console.log('Query created');

  return new Promise((resolve, reject) => {
    console.log('Running query...');
    client.runQuery(query, resolve, reject);

As you see, fetchData accepts the client, source name and query configuration as parameters. It prepares a query and runs it, returning a Promise which may resolve with actual source data.
Note: currently runQuery doesn’t return a Promise, which would be very handy, so we need to wrap it manually.

At this point, everything is set up and we can actually try running our script:

$ node index.js

Give it some time to create underlying connection and send a query, and you should see something similar to this:

Client ready
    Query created
    Running query...
    Received data: [ { group: [ 'Female' ],
        current: { count: 35596, metrics: [Object] } },
      { group: [ 'Male' ],
        current: { count: 35617, metrics: [Object] } } ]

Run index.js in Node

Zoomdata SDK in action