---
title: "How do I use Node.js with the API plugin?"
description: "Using Node.js with the API plugin requires installing Node.js, npm, and the xmlrpc package on the server. The process involves setting up an API sampler and running a Node.js script to create a view on your netprobe."
url: "https://docs.itrsgroup.com/docs/faq/geneos/115004019005-geneos-how-do-i-use-node-js-with-the-api-plugin/index.html"
---
Before we proceed you need to have both the node module and npm manager installed onto the server. **npm** is the default [package manager](https://en.wikipedia.org/wiki/Package_manager "Package manager") for the [JavaScript](https://en.wikipedia.org/wiki/JavaScript "JavaScript") runtime environment [Node.js](https://en.wikipedia.org/wiki/Node.js "Node.js").

With the npm command please the xmlrpc package. For more information please see <https://www.npmjs.com/package/xmlrpc>

```
npm install xmlrpc
```

With node and npm installed. For this example, an API sampler named "myAPI" needs to be set up before the following script is initiated. Please read the comments carefully:

```
// Must be installed via npm before running this script
var xmlrpc = require('xmlrpc');

// For I am the XMLRPC client, I need to contact my XMLRPC server (in our case the NetProbe)
// So let's us creates a XML-RPC client. Pass the host information on which netprobe server to
// make the XML-RPC calls. {host: <Netprobe hostname>, port: <Netprobe port>, path: '/xmlrpc'}
var client = xmlrpc.createClient({host: 'nysupsvr06', port: 53945, path: '/xmlrpc'});

// Sends a method call to the XML-RPC netprobe server to create the view
// To keep in mind to create a view ['Dataview Name', 'Dataview grouping']
client.methodCall('InfraSvr06.myAPI.createview', ['Node-queues','NodeJS'], function (error, value)
{
if (error) {

// You can comment this part out, but I suggest to keep for debug purposes
// and to understand any error that may come your way. I will be using this through out the Node.js script
console.log('error:', error);
console.log('req headers:', error.req && error.req._header);
console.log('res code:', error.res && error.res.statusCode);
console.log('res body:', error.body);
} else {

// Expose value/response
console.log('value:', value);
}
});

// Let's do a headline
client.methodCall('InfraSvr06.myAPI.NodeJS-Node-queues.addHeadline', ['totalQueues'], function (error, value)
{
if (error) {
console.log('error:', error);
console.log('req headers:', error.req && error.req._header);
console.log('res code:', error.res && error.res.statusCode);
console.log('res body:', error.body);
} else {
console.log('value:', value);
}
});

// Let's do another headline!
client.methodCall('InfraSvr06.myAPI.NodeJS-Node-queues.addHeadline', ['queuesOffline'], function (error, value)
{
if (error) {
console.log('error:', error);
console.log('req headers:', error.req && error.req._header);
console.log('res code:', error.res && error.res.statusCode);
console.log('res body:', error.body);
} else {
console.log('value:', value);
}
});

// Using a multi-dimensional array for our Dataview
var DataviewMatrix = [
["queueName", "currentSize", "maxSize", "currentUtilisation", "status"], // Keep in mind, the First is actually your column headings
["queue1", "332", "30000", "0.11", "online"], // This is where you will be starting your first row.
["queue2", "0", "90000", "0", "offline"],
["queue3", "7331", "45000", "0.16", "online"]
];

// You have to send one parameter a time to the updateEntireTable call
// This part varies from language to language
// var YourVarName = [DataviewMatrix];
var MyView = [DataviewMatrix];

// The matrix of our Dataview.
client.methodCall('InfraSvr06.myAPI.NodeJS-Node-queues.updateEntireTable', MyView, function (error, value)
{
if (error) {
console.log('error:', error);
console.log('req headers:', error.req && error.req._header);
console.log('res code:', error.res && error.res.statusCode);
console.log('res body:', error.body);
} else {
console.log('value:', value);
}
});

// Updating the first headline with data
var params = ["totalQueues", 3];
client.methodCall('InfraSvr06.myAPI.NodeJS-Node-queues.updateHeadline', [params[0], params[1]], function (error, value)
{
if (error) {
console.log('error:', error);
console.log('req headers:', error.req && error.req._header);
console.log('res code:', error.res && error.res.statusCode);
console.log('res body:', error.body);
} else {
console.log('value:', value);
}
});

// Updating the second headline with data
var params = ["queuesOffline", 1];
client.methodCall('InfraSvr06.myAPI.NodeJS-Node-queues.updateHeadline', [params[0], params[1]], function (error, value)
{
if (error) {
console.log('error:', error);
console.log('req headers:', error.req && error.req._header);
console.log('res code:', error.res && error.res.statusCode);
console.log('res body:', error.body);
} else {
console.log('value:', value);
}
});

// Boolean for our timed loop
// You can have this set to false to turn off the loop
var bSendTestData = true;
var ViewCell = 'queue2.currentSize'; // Imagine this as a "x.y" coordinates, we're updating "row name"."column name"
var HeadlineCell = 'queuesOffline'; // Updating the headline cell as well

// Setting the first interval as 0
var index = 0;
setInterval(function(){
// Keep incrementing by one
index++;
client.methodCall('InfraSvr06.myAPI.NodeJS-Node-queues.updateTableCell', [ViewCell, index], function (error, value)
{
if (error) {
console.log('error:', error);
console.log('req headers:', error.req && error.req._header);
console.log('res code:', error.res && error.res.statusCode);
console.log('res body:', error.body);
} else {
console.log('value:', value);
}
});
client.methodCall('InfraSvr06.myAPI.NodeJS-Node-queues.updateHeadline', [HeadlineCell, index], function (error, value)
{
if (error) {
console.log('error:', error);
console.log('req headers:', error.req && error.req._header);
console.log('res code:', error.res && error.res.statusCode);
console.log('res body:', error.body);
} else {
console.log('value:', value);
}
});
}, 1000)
```

In this scenario I'm referencing the previous script as "YourScript.js", Next run your node.js script with the following command :

```
node YourScript.js
```

This script should create the following view on your netprobe with "myAPI" sampler:

![Geneos - How do I use Node.js with the API plugin?](https://docscdn.itrsgroup.com/faq/images/geneos/115004019005-remote-005-NodeJS_API-15154bc22f47.png)


