Here is my code. Here I replaced my subscription id with "subid".
const { DefaultAzureCredential } = require("@azure/identity");
const { NetworkManagementClient } = require("@azure/arm-network");
const subscriptionId="subid"
const resourceGroupName = "azure_dep";
const gatewayName = "VNet2GW";
// Set up the credentials and network management client
const credential = new DefaultAzureCredential();
const client = new NetworkManagementClient(credential, subscriptionId);
async function vpnGatewayListBySubscription() {
const resArray = new Array();
for await (let item of client.vpnGateways.list()) {
resArray.push(item);
}
console.log(resArray);
}
vpnGatewayListBySubscription();
Output is just an empty list like this []. But I have 2 VPN gateways under my sub. Further, I can list them using Azure CLI. But I can't get the list using javascript.