Skip to content

Commit 806d5c4

Browse files
committed
feedback
1 parent e35de3c commit 806d5c4

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed

articles/azure-functions/functions-node-upgrade-v4.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ ms.topic: how-to
99

1010
# Upgrade to version 4 of the Node.js programming model for Azure Functions
1111

12-
The Node.js programming model for Azure Functions defines how you author serverless code in JavaScript or TypeScript. The version of the programming model matches the version of the [`@azure/functions`](https://www.npmjs.com/package/@azure/functions) npm package that should be included with your app. This article discusses the differences between both versions and how to upgrade an existing v3 app. If you want to create a brand new v4 app, see the tutorial for either [VS Code](./create-first-function-cli-node.md) or [Azure Functions Core Tools](./create-first-function-vs-code-node.md).
12+
This article discusses the differences between version 3 and version 4 of the Node.js programming model and how to upgrade an existing v3 app. If you want to create a brand new v4 app instead of upgrading an existing v3 app, see the tutorial for either [VS Code](./create-first-function-cli-node.md) or [Azure Functions Core Tools](./create-first-function-vs-code-node.md). This article uses "TIP" sections to highlight the most important concrete actions you should take to upgrade your app.
1313

1414
Version 4 was designed with the following goals in mind:
1515

1616
- Provide a familiar and intuitive experience to Node.js developers
1717
- Make the file structure flexible with support for full customization
1818
- Switch to a code-centric approach for defining function configuration
1919

20-
> [!NOTE]
21-
> v4 of the Node.js programming model is currently in public preview. This version number is _not_ the same thing as the Azure Functions [runtime version](./functions-versions.md), which is coincidentally using "4" as its latest major version. Lastly, you can't mix v3 and v4 of the programming models.
20+
[!INCLUDE [Programming Model Considerations](../../includes/functions-nodejs-model-considerations.md)]
2221

2322
## Requirements
2423

@@ -35,7 +34,7 @@ Version 4 of the Node.js programming model requires the following minimum versio
3534
For the first time, the [`@azure/functions`](https://www.npmjs.com/package/@azure/functions) npm package contains the primary source code that backs the Node.js programming model for Azure Functions. Previously, that code shipped directly in Azure and the npm package only had the TypeScript types. Moving forward both JavaScript and TypeScript users need to include this package in their app. v3 apps _can_ include the npm package, but it isn't required.
3635

3736
> [!TIP]
38-
> _**Action Item**_: Make sure the `@azure/functions` package is listed in the `dependencies` section (not `devDependencies`) of your `package.json` file. You can install v4 with the command
37+
> Make sure the `@azure/functions` package is listed in the `dependencies` section (not `devDependencies`) of your `package.json` file. You can install v4 with the command
3938
> ```
4039
> npm install @azure/functions@preview
4140
> ```
@@ -51,21 +50,18 @@ In v4 of the programming model, you can structure your code however you want. Th
5150
- `src/functions/*.js`
5251
5352
> [!TIP]
54-
> _**Action Item**_: Make sure you define a `main` field in your `package.json` file
53+
> Make sure you define a `main` field in your `package.json` file
5554
5655
## Switch the order of arguments
5756
5857
The trigger input is now the first argument to your function handler instead of the invocation context. The invocation context, now the second argument, was simplified in v4 and isn't as required as the trigger input - it can be left off if you aren't using it.
5958
6059
> [!TIP]
61-
> _**Action Item**_: Switch the order of your arguments. For example if you are using an http trigger, switch `(context, request)` to either `(request, context)` or just `(request)` if you aren't using the context.
60+
> Switch the order of your arguments. For example if you are using an http trigger, switch `(context, request)` to either `(request, context)` or just `(request)` if you aren't using the context.
6261
6362
## Define your function in code
6463
65-
Say goodbye 👋 to `function.json` files! All of the configuration that you were previously specifying in a `function.json` file is now defined directly in your TypeScript or JavaScript files. In addition, many properties now have a default so that you don't have to specify them every time.
66-
67-
> [!WARNING]
68-
> You can't mix the v3 and v4 programming models. As soon as you register one v4 function in your app, any v3 functions registered in `function.json` files will be ignored.
64+
Say goodbye 👋 to `function.json` files! All of the configuration that was previously specified in a `function.json` file is now defined directly in your TypeScript or JavaScript files. In addition, many properties now have a default so that you don't have to specify them every time.
6965
7066
# [v4](#tab/v4)
7167
@@ -86,8 +82,6 @@ app.http('helloWorld1', {
8682
});
8783
```
8884
89-
No `function.json` file! ✨
90-
9185
# [v3](#tab/v3)
9286

9387
```javascript
@@ -129,7 +123,7 @@ module.exports = async function (context, req) {
129123
---
130124

131125
> [!TIP]
132-
> _**Action Item**_: Move the config from your `function.json` file to your code. The type of the trigger will correspond to a method on the `app` object in the new model. For example, if you use an `httpTrigger` type in `function.json`, you will now call `app.http()` in your code to register the function. If you use `timerTrigger`, you will now call `app.timer()` and so on.
126+
> Move the config from your `function.json` file to your code. The type of the trigger will correspond to a method on the `app` object in the new model. For example, if you use an `httpTrigger` type in `function.json`, you will now call `app.http()` in your code to register the function. If you use `timerTrigger`, you will now call `app.timer()` and so on.
133127
134128

135129
## Review your usage of context
@@ -163,7 +157,7 @@ async function helloWorld1(context, request) {
163157
---
164158
165159
> [!TIP]
166-
> _**Action Item**_: Make sure you aren't using `context.req` or `context.bindings` to get the input.
160+
> Make sure you aren't using `context.req` or `context.bindings` to get the input.
167161
168162
### Set the primary output as your return value
169163
@@ -205,7 +199,7 @@ return {
205199
---
206200
207201
> [!TIP]
208-
> _**Action Item**_: Make sure you are always returning the output in your function handler, instead of setting it with the `context` object.
202+
> Make sure you are always returning the output in your function handler, instead of setting it with the `context` object.
209203
210204
### Create a test context
211205
@@ -329,7 +323,7 @@ The http request and response types are now a subset of the [fetch standard](htt
329323
---
330324
331325
> [!TIP]
332-
> _**Action Item**_: Update any logic using the http request or response types to match the new methods. If you are using TypeScript, you should receive build errors if you use old methods.
326+
> Update any logic using the http request or response types to match the new methods. If you are using TypeScript, you should receive build errors if you use old methods.
333327
334328
## Troubleshooting
335329

articles/azure-functions/functions-reference-node.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,17 @@ zone_pivot_groups: functions-nodejs-model
1515
This guide is an introduction to developing Azure Functions using JavaScript or TypeScript. The article assumes that you've already read the [Azure Functions developer guide](functions-reference.md).
1616

1717
> [!IMPORTANT]
18-
> The content of this article changes based on your choice of the Node.js programming model in the selector at the top of this page. The version you choose should match the version of the [`@azure/functions`](https://www.npmjs.com/package/@azure/functions) npm package you are using in your app. If you do not have that package listed in your `package.json`, the default is v3. Learn more about the differences between v3 and the new v4 programming model in the [upgrade guide](./functions-node-upgrade-v4.md). v4 is currently in public preview.
18+
> The content of this article changes based on your choice of the Node.js programming model in the selector at the top of this page. The version you choose should match the version of the [`@azure/functions`](https://www.npmjs.com/package/@azure/functions) npm package you are using in your app. If you do not have that package listed in your `package.json`, the default is v3. Learn more about the differences between v3 and v4 in the [upgrade guide](./functions-node-upgrade-v4.md).
1919
2020
As a JavaScript developer, you might also be interested in one of the following articles:
2121

2222
| Getting started | Concepts| Guided learning |
2323
| -- | -- | -- |
2424
| <ul><li>[Node.js function using Visual Studio Code](./create-first-function-vs-code-node.md)</li><li>[Node.js function with terminal/command prompt](./create-first-function-cli-node.md)</li><li>[Node.js function using the Azure portal](functions-create-function-app-portal.md)</li></ul> | <ul><li>[Developer guide](functions-reference.md)</li><li>[Hosting options](functions-scale.md)</li><li>[TypeScript functions](#typescript)</li><li>[Performance&nbsp; considerations](functions-best-practices.md)</li></ul> | <ul><li>[Create serverless applications](/training/paths/create-serverless-applications/)</li><li>[Refactor Node.js and Express APIs to Serverless APIs](/training/modules/shift-nodejs-express-apis-serverless/)</li></ul> |
2525

26-
## Programming model
26+
[!INCLUDE [Programming Model Considerations](../../includes/functions-nodejs-model-considerations.md)]
2727

28-
The "programming model" as discussed in this article loosely represents the Node.js layer of Azure Functions. If you are authoring code in JavaScript or TypeScript, the code patterns you use are governed by the programming model. For example, it defines how you register a function, get a function's input, or interact with the invocation context. The programming model version is strictly tied to the version of the [`@azure/functions`](https://www.npmjs.com/package/@azure/functions) npm package and is _not_ the same thing as the Azure Functions [runtime version](./functions-versions.md), even if the major version numbers are coincidentally similar.
29-
30-
> [!NOTE]
31-
> You can only use one major version of the programming model at a time.
32-
33-
### Supported versions
28+
## Supported versions
3429

3530
The following table shows each version of the Node.js programming model along with its supported versions of the Azure Functions runtime and Node.js.
3631

@@ -261,9 +256,6 @@ app.http('httpTrigger1', {
261256
});
262257
```
263258

264-
> [!NOTE]
265-
> You can't mix the v3 and v4 programming models. As soon as you register one v4 function in your app, any v3 functions registered in `function.json` files will be ignored.
266-
267259
## Inputs and outputs
268260

269261
Your function is required to have exactly one primary input called the trigger. It may also have secondary inputs, a primary output called the return output, and/or secondary outputs. Inputs and outputs are also referred to as bindings outside the context of the Node.js programming model. Before v4 of the model, these bindings were configured in `function.json` files.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: include file
3+
description: include file
4+
author: ejizba
5+
ms.service: azure-functions
6+
ms.topic: include
7+
ms.date: 03/21/2023
8+
ms.author: erijiz
9+
ms.custom: include file
10+
---
11+
12+
## Considerations
13+
14+
- The Node.js "programming model" should not be confused with the Azure Functions "runtime".
15+
- _**Programming model**_: The part of Azure Functions specific to JavaScript and TypeScript that governs how you author your code. For example it determines how you register a function, get a function's input, or interact with the invocation context.
16+
- _**Runtime**_: The central part of Azure Functions that governs underlying behavior shared across all languages.
17+
- The Node.js programming model is versioned independently of the Azure Functions [runtime](./functions-versions.md). The programming model version is strictly tied to the version of the [`@azure/functions`](https://www.npmjs.com/package/@azure/functions) npm package. Both the runtime and the programming model use "4" as their latest major version, but that is purely a coincidence.
18+
- Keep in mind that you can't mix the v3 and v4 programming models in the same function app. As soon as you register one v4 function in your app, any v3 functions registered in `function.json` files will be ignored.
19+
20+
> [!NOTE]
21+
> Version 4 of the Node.js programming model is currently in public preview.

0 commit comments

Comments
 (0)