Skip to content

Commit 703de87

Browse files
authored
Merge pull request #71344 from qiaozha/patch-1
Update cdn-app-dev-node.md
2 parents 33aa749 + 1a9cd2c commit 703de87

File tree

1 file changed

+20
-40
lines changed

1 file changed

+20
-40
lines changed

articles/cdn/cdn-app-dev-node.md

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ms.workload: tbd
1313
ms.tgt_pltfrm: na
1414
ms.devlang: na
1515
ms.topic: how-to
16-
ms.date: 01/23/2017
16+
ms.date: 04/02/2021
1717
ms.author: mazha
1818
ms.custom: devx-track-js
1919
---
@@ -24,14 +24,10 @@ ms.custom: devx-track-js
2424
>
2525
>
2626
27-
You can use the [Azure CDN SDK for Node.js](https://www.npmjs.com/package/azure-arm-cdn) to automate creation and management of CDN profiles and endpoints. This tutorial walks through the creation of a simple Node.js console application that demonstrates several of the available operations. This tutorial is not intended to describe all aspects of the Azure CDN SDK for Node.js in detail.
27+
You can use the [Azure CDN SDK for JavaScript](https://www.npmjs.com/package/@azure/arm-cdn) to automate creation and management of CDN profiles and endpoints. This tutorial walks through the creation of a simple Node.js console application that demonstrates several of the available operations. This tutorial is not intended to describe all aspects of the Azure CDN SDK for JavaScript in detail.
2828

29-
To complete this tutorial, you should already have [Node.js](https://www.nodejs.org) **4.x.x** or higher installed and configured. You can use any text editor you want to create your Node.js application. To write this tutorial, I used [Visual Studio Code](https://code.visualstudio.com).
29+
To complete this tutorial, you should already have [Node.js](https://www.nodejs.org) **6.x.x** or higher installed and configured. You can use any text editor you want to create your Node.js application. To write this tutorial, I used [Visual Studio Code](https://code.visualstudio.com).
3030

31-
> [!TIP]
32-
> The [completed project from this tutorial](https://code.msdn.microsoft.com/Azure-CDN-SDK-for-Nodejs-c712bc74) is available for download on MSDN.
33-
>
34-
>
3531

3632
[!INCLUDE [cdn-app-dev-prep](../../includes/cdn-app-dev-prep.md)]
3733

@@ -48,11 +44,11 @@ You will then be presented a series of questions to initialize your project. Fo
4844

4945
![NPM init output](./media/cdn-app-dev-node/cdn-npm-init.png)
5046

51-
Our project is now initialized with a *packages.json* file. Our project is going to use some Azure libraries contained in NPM packages. We'll use the Azure Client Runtime for Node.js (ms-rest-azure) and the Azure CDN Client Library for Node.js (azure-arm-cd). Let's add those to the project as dependencies.
47+
Our project is now initialized with a *packages.json* file. Our project is going to use some Azure libraries contained in NPM packages. We'll use the library for Azure Active Directory authentication in Node.js (@azure/ms-rest-nodeauth) and the Azure CDN Client Library for JavaScript (@azure/arm-cdn). Let's add those to the project as dependencies.
5248

5349
```console
54-
npm install --save ms-rest-azure
55-
npm install --save azure-arm-cdn
50+
npm install --save @azure/ms-rest-nodeauth
51+
npm install --save @azure/arm-cdn
5652
```
5753

5854
After the packages are done installing, the *package.json* file should look similar to this example (version numbers may differ):
@@ -69,8 +65,8 @@ After the packages are done installing, the *package.json* file should look simi
6965
"author": "Cam Soper",
7066
"license": "MIT",
7167
"dependencies": {
72-
"azure-arm-cdn": "^0.2.1",
73-
"ms-rest-azure": "^1.14.4"
68+
"@azure/arm-cdn": "^5.2.0",
69+
"@azure/ms-rest-nodeauth": "^3.0.0"
7470
}
7571
}
7672
```
@@ -83,8 +79,8 @@ With *app.js* open in our editor, let's get the basic structure of our program w
8379
1. Add the "requires" for our NPM packages at the top with the following:
8480

8581
``` javascript
86-
var msRestAzure = require('ms-rest-azure');
87-
var cdnManagementClient = require('azure-arm-cdn');
82+
var msRestAzure = require('@azure/ms-rest-nodeauth');
83+
const { CdnManagementClient } = require('@azure/arm-cdn');
8884
```
8985
2. We need to define some constants our methods will use. Add the following. Be sure to replace the placeholders, including the **<angle brackets>**, with your own values as needed.
9086

@@ -103,23 +99,9 @@ With *app.js* open in our editor, let's get the basic structure of our program w
10399
104100
``` javascript
105101
var credentials = new msRestAzure.ApplicationTokenCredentials(clientId, tenantId, clientSecret);
106-
var cdnClient = new cdnManagementClient(credentials, subscriptionId);
102+
var cdnClient = new CdnManagementClient(credentials, subscriptionId);
107103
```
108-
109-
If you are using individual user authentication, these two lines will look slightly different.
110-
111-
> [!IMPORTANT]
112-
> Only use this code sample if you are choosing to have individual user authentication instead of a service principal. Be careful to guard your individual user credentials and keep them secret.
113-
>
114-
>
115-
116-
``` javascript
117-
var credentials = new msRestAzure.UserTokenCredentials(clientId,
118-
tenantId, '<username>', '<password>', '<redirect URI>');
119-
var cdnClient = new cdnManagementClient(credentials, subscriptionId);
120-
```
121-
122-
Be sure to replace the items in **&lt;angle brackets&gt;** with the correct information. For `<redirect URI>`, use the redirect URI you entered when you registered the application in Azure AD.
104+
123105
4. Our Node.js console application is going to take some command-line parameters. Let's validate that at least one parameter was passed.
124106

125107
```javascript
@@ -232,7 +214,7 @@ function cdnList(){
232214
case "endpoints":
233215
requireParms(3);
234216
console.log("Listing endpoints...");
235-
cdnClient.endpoints.listByProfile(parms[2], resourceGroupName, callback);
217+
cdnClient.endpoints.listByProfile(resourceGroupName, parms[2], callback);
236218
break;
237219
238220
default:
@@ -275,7 +257,7 @@ function cdnCreateProfile() {
275257
}
276258
};
277259
278-
cdnClient.profiles.create(parms[2], standardCreateParameters, resourceGroupName, callback);
260+
cdnClient.profiles.create( resourceGroupName, parms[2], standardCreateParameters, callback);
279261
}
280262
281263
// create endpoint <profile name> <endpoint name> <origin hostname>
@@ -290,7 +272,7 @@ function cdnCreateEndpoint() {
290272
}]
291273
};
292274
293-
cdnClient.endpoints.create(parms[3], endpointProperties, parms[2], resourceGroupName, callback);
275+
cdnClient.endpoints.create(resourceGroupName, parms[2], parms[3], endpointProperties, callback);
294276
}
295277
```
296278

@@ -303,7 +285,7 @@ function cdnPurge() {
303285
requireParms(4);
304286
console.log("Purging endpoint...");
305287
var purgeContentPaths = [ parms[3] ];
306-
cdnClient.endpoints.purgeContent(parms[2], parms[1], resourceGroupName, purgeContentPaths, callback);
288+
cdnClient.endpoints.purgeContent(resourceGroupName, parms[2], parms[3], purgeContentPaths, callback);
307289
}
308290
```
309291

@@ -319,14 +301,14 @@ function cdnDelete() {
319301
case "profile":
320302
requireParms(3);
321303
console.log("Deleting profile...");
322-
cdnClient.profiles.deleteIfExists(parms[2], resourceGroupName, callback);
304+
cdnClient.profiles.deleteMethod(resourceGroupName, parms[2], callback);
323305
break;
324306

325307
// delete endpoint <profile name> <endpoint name>
326308
case "endpoint":
327309
requireParms(4);
328310
console.log("Deleting endpoint...");
329-
cdnClient.endpoints.deleteIfExists(parms[3], parms[2], resourceGroupName, callback);
311+
cdnClient.endpoints.deleteMethod(resourceGroupName, parms[2], parms[3], callback);
330312
break;
331313

332314
default:
@@ -361,11 +343,9 @@ Finally, let's delete our profile.
361343
![Delete profile](./media/cdn-app-dev-node/cdn-delete-profile.png)
362344

363345
## Next Steps
364-
To see the completed project from this walkthrough, [download the sample](https://code.msdn.microsoft.com/Azure-CDN-SDK-for-Nodejs-c712bc74).
365346

366-
To see the reference for the Azure CDN SDK for Node.js, view the [reference](https://azure.github.io/azure-sdk-for-node/azure-arm-cdn/latest/).
347+
To see the reference for the Azure CDN SDK for JavaScript, view the [reference](https://docs.microsoft.com/javascript/api/@azure/arm-cdn).
367348

368-
To find additional documentation on the Azure SDK for Node.js, view the [full reference](https://azure.github.io/azure-sdk-for-node/).
349+
To find additional documentation on the Azure SDK for JavaScript, view the [full reference](https://docs.microsoft.com/javascript/api/?view=azure-node-latest).
369350

370351
Manage your CDN resources with [PowerShell](cdn-manage-powershell.md).
371-

0 commit comments

Comments
 (0)