Hello I am new to Azure and Javascript, I am trying to run a code in order to get the list of VMs and its owners, I want to use Resource Graph service as it seems to be faster.
My inventory is more than 1000 so I need to run the function multiple times because of the pagination. The first 2 times it runs all good, but on the 3rd time it gives me this error, not sure why I am receiving this since the first 2 ran ok.
I do not see too much documentation for Javascript and this module, thus I am requesting your help.
let query = async (x) => {
//creates the client
credentials = new ClientSecretCredential(tenantId, clientId, secret);
let client = new ResourceGraphClient(credentials);
//in a loop to get the results since the limit is 1000 results per call/query,
//if you have more than 1000 you will need to use skip token variable provided in the answer
do
{
try
{
//first time is empty
if (skipToken_=="")
{
result = await client.resources(
{
query: x
},
{ resultFormat: "objectArray" }
);
console.log("Records: " + result.totalRecords);
console.log(result.data);
console.log(result.skipToken);
skipToken_=result.skipToken;
console.log(result.data[0]);
console.log(result);
}
else
{
result = await client.resources(
{
query: x
},
{ resultFormat: "objectArray" },
{skipToken:skipToken_}
);
console.log("Records: " + result.totalRecords);
console.log(result.data);
console.log(result.skipToken);
skipToken_=result.skipToken;
console.log(result.data[0]);
console.log(result);
}
} catch (error) {console.log(error)}
}while (skipToken_!= "");
}
// this calls a query already saved instead of using commands
query("{{/subscriptions/*****/resourceGroups/******}}");
the error is below:
TypeError: cb is not a function
at c:\Users\...\Desktop\last day work for cloud\node_modules\@azure\ms-rest-js\dist\msRest.node.js:4949:48
I googled it and found that cb is the callback function, what is odd is that as I said the first 2 times works well but on the third it breaks. Since this is part of the library I am thinking there is an error with the package/module/library?
TypeError: cb is not a function at c:\Users...\Desktop\last day work for cloud\node_modules@azure\ms-rest-js\dist\msRest.node.js:4949:48
To resolve the above error, try either of the following options as suggested by allaura-dev:
Option 1:
C:\Users(your username)\AppData\Roaming, delete the npm foldernpm cache folder, Run npm clean cache —forceOption 2:
C:\Users(your username)\AppData\Roaming, delete the npm foldermom cache folder, Run npm clean cache —forceNodejs is deleted and uninstalled then reinstall Nodejs.Reference: error cb.apply is not a function