Skip to content

Commit 0e2bd49

Browse files
Merge pull request #299334 from TimShererWithAquent/us424061-03
Freshness Edit: Azure Functions (3 of several)
2 parents 00d376d + b7aa8e1 commit 0e2bd49

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

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

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: Node.js developer reference for Azure Functions
3-
description: Understand how to develop functions by using Node.js.
3+
description: Learn how to develop serverless applications using Node.js in Azure Functions, including triggers, bindings, and best practices.
44
ms.assetid: 45dedd78-3ff9-411f-bb4b-16d29a11384c
55
ms.topic: conceptual
6-
ms.date: 02/28/2024
6+
ms.date: 05/05/2025
77
ms.devlang: javascript
88
# ms.devlang: javascript, typescript
99
ms.custom: devx-track-js, vscode-azure-extension-update-not-needed
@@ -15,7 +15,7 @@ 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 have 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 v4 in the [migration guide](./functions-node-upgrade-v4.md).
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're using in your app. If you don't have that package listed in your `package.json`, the default is v3. Learn more about the differences between v3 and v4 in the [migration guide](./functions-node-upgrade-v4.md).
1919
2020
As a Node.js developer, you might also be interested in one of the following articles:
2121

@@ -44,7 +44,7 @@ The following table shows each version of the Node.js programming model along wi
4444

4545
The required folder structure for a JavaScript project looks like the following example:
4646

47-
```
47+
```text
4848
<project_root>/
4949
| - .vscode/
5050
| - node_modules/
@@ -74,7 +74,7 @@ The main project folder, *<project_root>*, can contain the following files:
7474

7575
The required folder structure for a TypeScript project looks like the following example:
7676

77-
```
77+
```text
7878
<project_root>/
7979
| - .vscode/
8080
| - dist/
@@ -114,7 +114,7 @@ The main project folder, *<project_root>*, can contain the following files:
114114

115115
The recommended folder structure for a JavaScript project looks like the following example:
116116

117-
```
117+
```text
118118
<project_root>/
119119
| - .vscode/
120120
| - node_modules/
@@ -146,7 +146,7 @@ The main project folder, *<project_root>*, can contain the following files:
146146

147147
The recommended folder structure for a TypeScript project looks like the following example:
148148

149-
```
149+
```text
150150
<project_root>/
151151
| - .vscode/
152152
| - dist/
@@ -292,7 +292,7 @@ The programming model loads your functions based on the `main` field in your `pa
292292

293293
In order to register a function, you must import the `app` object from the `@azure/functions` npm module and call the method specific to your trigger type. The first argument when registering a function is the function name. The second argument is an `options` object specifying configuration for your trigger, your handler, and any other inputs or outputs. In some cases where trigger configuration isn't necessary, you can pass the handler directly as the second argument instead of an `options` object.
294294

295-
Registering a function can be done from any file in your project, as long as that file is loaded (directly or indirectly) based on the `main` field in your `package.json` file. The function should be registered at a global scope because you can't register functions once executions have started.
295+
Registering a function can be done from any file in your project, as long as that file is loaded (directly or indirectly) based on the `main` field in your `package.json` file. The function should be registered at a global scope because you can't register functions once executions start.
296296

297297
The following example is a simple function that logs that it was triggered and responds with `Hello, world!`:
298298

@@ -336,15 +336,15 @@ app.http('helloWorld1', {
336336

337337
::: zone pivot="nodejs-model-v3"
338338

339-
Your function is required to have exactly one primary input called the trigger. It may also have secondary inputs and/or outputs. Inputs and outputs are configured in your `function.json` files and are also referred to as [bindings](./functions-triggers-bindings.md).
339+
Your function is required to have exactly one primary input called the trigger. It might also have secondary inputs and/or outputs. Inputs and outputs are configured in your `function.json` files and are also referred to as [bindings](./functions-triggers-bindings.md).
340340

341341
### Inputs
342342

343343
Inputs are bindings with `direction` set to `in`. The main difference between a trigger and a secondary input is that the `type` for a trigger ends in `Trigger`, for example type [`blobTrigger`](./functions-bindings-storage-blob-trigger.md) vs type [`blob`](./functions-bindings-storage-blob-input.md). Most functions only use a trigger, and not many secondary input types are supported.
344344

345345
Inputs can be accessed in several ways:
346346

347-
- **_[Recommended]_ As arguments passed to your function:** Use the arguments in the same order that they're defined in `function.json`. The `name` property defined in `function.json` doesn't need to match the name of your argument, although it's recommended for the sake of organization.
347+
- **_[Recommended]_ As arguments passed to your function:** Use the arguments in the same order that they're defined in `function.json`. The `name` property defined in `function.json` doesn't need to match the name of your argument, although we recommend it for the sake of organization.
348348

349349
# [JavaScript](#tab/javascript)
350350

@@ -530,7 +530,8 @@ Outputs are bindings with `direction` set to `out` and can be set in several way
530530

531531
### Bindings data type
532532

533-
You can use the `dataType` property on an input binding to change the type of your input, however it has some limitations:
533+
You can use the `dataType` property on an input binding to change the type of your input. However, the approach has some limitations:
534+
534535
- In Node.js, only `string` and `binary` are supported (`stream` isn't)
535536
- For HTTP inputs, the `dataType` property is ignored. Instead, use properties on the `request` object to get the body in your desired format. For more information, see [HTTP request](#http-request).
536537
@@ -584,7 +585,7 @@ export default queueTrigger1;
584585
585586
::: zone pivot="nodejs-model-v4"
586587
587-
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](./functions-triggers-bindings.md) outside the context of the Node.js programming model. Before v4 of the model, these bindings were configured in `function.json` files.
588+
Your function is required to have exactly one primary input called the trigger. It might also have secondary inputs, a primary output called the return output, and/or secondary outputs. Inputs and outputs are also referred to as [bindings](./functions-triggers-bindings.md) outside the context of the Node.js programming model. Before v4 of the model, these bindings were configured in `function.json` files.
588589
589590
### Trigger input
590591
@@ -666,7 +667,7 @@ app.timer('timerTrigger1', {
666667
667668
### Extra inputs and outputs
668669
669-
In addition to the trigger and return, you may specify extra inputs or outputs on the `options` argument when registering a function. The `input` and `output` objects exported from the `@azure/functions` module provide type-specific methods to help construct the configuration. During execution, you get or set the values with `context.extraInputs.get` or `context.extraOutputs.set`, passing in the original configuration object as the first argument.
670+
In addition to the trigger and return, you might specify extra inputs or outputs on the `options` argument when registering a function. The `input` and `output` objects exported from the `@azure/functions` module provide type-specific methods to help construct the configuration. During execution, you get or set the values with `context.extraInputs.get` or `context.extraOutputs.set`, passing in the original configuration object as the first argument.
670671
671672
The following example is a function triggered by a [storage queue](./functions-bindings-storage-queue-trigger.md), with an extra [storage blob input](./functions-bindings-storage-blob-input.md) that is copied to an extra [storage blob output](./functions-bindings-storage-blob-output.md). The queue message should be the name of a file and replaces `{queueTrigger}` as the blob name to be copied, with the help of a [binding expression](./functions-bindings-expressions-patterns.md).
672673
@@ -909,7 +910,7 @@ export default httpTrigger;
909910
910911
---
911912
912-
Now, it's recommended to remove the call to `context.done()` and mark your function as async so that it returns a promise (even if you don't `await` anything). As soon as your function finishes (in other words, the returned promise resolves), the v3 model knows your function is done.
913+
We recommend that you remove the call to `context.done()` and mark your function as async so that it returns a promise (even if you don't `await` anything). As soon as your function finishes (in other words, the returned promise resolves), the v3 model knows your function is done.
913914
914915
# [JavaScript](#tab/javascript)
915916
@@ -974,7 +975,7 @@ For more information, see [`retry-policies`](./functions-bindings-errors.md#retr
974975
In Azure Functions, it's recommended to use `context.log()` to write logs. Azure Functions integrates with Azure Application Insights to better capture your function app logs. Application Insights, part of Azure Monitor, provides facilities for collection, visual rendering, and analysis of both application logs and your trace outputs. To learn more, see [monitoring Azure Functions](functions-monitoring.md).
975976
976977
> [!NOTE]
977-
> If you use the alternative Node.js `console.log` method, those logs are tracked at the app-level and will *not* be associated with any specific function. It is *highly recommended* to use `context` for logging instead of `console` so that all logs are associated with a specific function.
978+
> If you use the alternative Node.js `console.log` method, those logs are tracked at the app-level and will *not* be associated with any specific function. We *highly recommend* that your use `context` for logging instead of `console` so that all logs are associated with a specific function.
978979
979980
The following example writes a log at the default "information" level, including the invocation ID:
980981
@@ -1235,7 +1236,7 @@ In order to access a request or response's body, the following methods can be us
12351236
| **`text()`** | `Promise<string>` |
12361237
12371238
> [!NOTE]
1238-
> The body functions can be run only once; subsequent calls will resolve with empty strings/ArrayBuffers.
1239+
> The body functions can be run only once. Subsequent calls resolve with empty strings/ArrayBuffers.
12391240
12401241
::: zone-end
12411242
@@ -1586,7 +1587,7 @@ By default, Azure Functions automatically monitors the load on your application
15861587
This scaling behavior is sufficient for many Node.js applications. For CPU-bound applications, you can improve performance further by using multiple language worker processes. You can increase the number of worker processes per host from the default of 1 up to a max of 10 by using the [FUNCTIONS_WORKER_PROCESS_COUNT](functions-app-settings.md#functions_worker_process_count) application setting. Azure Functions then tries to evenly distribute simultaneous function invocations across these workers. This behavior makes it less likely that a CPU-intensive function blocks other functions from running. The setting applies to each host that Azure Functions creates when scaling out your application to meet demand.
15871588
15881589
> [!WARNING]
1589-
> Use the `FUNCTIONS_WORKER_PROCESS_COUNT` setting with caution. Multiple processes running in the same instance can lead to unpredictable behavior and increase function load times. If you use this setting, it's *highly recommended* to offset these downsides by [running from a package file](./run-functions-from-deployment-package.md).
1590+
> Use the `FUNCTIONS_WORKER_PROCESS_COUNT` setting with caution. Multiple processes running in the same instance can lead to unpredictable behavior and increase function load times. If you use this setting, we *highly recommend* that you offset these downsides by [running from a package file](./run-functions-from-deployment-package.md).
15901591
15911592
## Node version
15921593
@@ -1598,11 +1599,11 @@ The way that you upgrade your Node.js version depends on the OS on which your fu
15981599
15991600
# [Windows](#tab/windows)
16001601
1601-
When running on Windows, the Node.js version is set by the [`WEBSITE_NODE_DEFAULT_VERSION`](./functions-app-settings.md#website_node_default_version) application setting. This setting can be updated either by using the Azure CLI or in the Azure portal.
1602+
When it runs on Windows, the Node.js version is set by the [`WEBSITE_NODE_DEFAULT_VERSION`](./functions-app-settings.md#website_node_default_version) application setting. This setting can be updated either by using the Azure CLI or in the Azure portal.
16021603
16031604
# [Linux](#tab/linux)
16041605
1605-
When running on Linux, the Node.js version is set by the [linuxfxversion](./functions-app-settings.md#linuxfxversion) site setting. This setting can be updated using the Azure CLI.
1606+
When it runs on Linux, the Node.js version is set by the [linuxFxVersion](./functions-app-settings.md#linuxfxversion) site setting. This setting can be updated using the Azure CLI.
16061607
16071608
---
16081609
@@ -1734,7 +1735,7 @@ There are several Functions environment variables specific to Node.js:
17341735
This setting allows you to specify custom arguments when starting your Node.js process. It's most often used locally to start the worker in debug mode, but can also be used in Azure if you need custom arguments.
17351736
17361737
> [!WARNING]
1737-
> If possible, avoid using `languageWorkers__node__arguments` in Azure because it can have a negative effect on cold start times. Rather than using pre-warmed workers, the runtime has to start a new worker from scratch with your custom arguments.
1738+
> If possible, avoid using `languageWorkers__node__arguments` in Azure because it can have a negative effect on cold start times. Rather than using prewarmed workers, the runtime has to start a new worker from scratch with your custom arguments.
17381739
17391740
#### logging__logLevel__Worker
17401741
@@ -1829,7 +1830,7 @@ By default, a JavaScript function is executed from `index.js`, a file that share
18291830

18301831
`scriptFile` can be used to get a folder structure that looks like the following example:
18311832

1832-
```
1833+
```text
18331834
<project_root>/
18341835
| - node_modules/
18351836
| - myFirstFunction/
@@ -1892,7 +1893,7 @@ export default { logHello };
18921893
18931894
## Local debugging
18941895
1895-
It's recommended to use VS Code for local debugging, which starts your Node.js process in debug mode automatically and attaches to the process for you. For more information, see [run the function locally](./create-first-function-vs-code-node.md#run-the-function-locally).
1896+
We recommend that you use VS Code for local debugging, which starts your Node.js process in debug mode automatically and attaches to the process for you. For more information, see [run the function locally](./create-first-function-vs-code-node.md#run-the-function-locally).
18961897
18971898
If you're using a different tool for debugging or want to start your Node.js process in debug mode manually, add `"languageWorkers__node__arguments": "--inspect"` under `Values` in your [local.settings.json](./functions-develop-local.md#local-settings-file). The `--inspect` argument tells Node.js to listen for a debug client, on port 9229 by default. For more information, see the [Node.js debugging guide](https://nodejs.org/en/learn/getting-started/debugging).
18981899
@@ -1927,7 +1928,7 @@ When writing Azure Functions in Node.js, you should write code using the `async`
19271928
19281929
::: zone pivot="nodejs-model-v4"
19291930
1930-
In the following example, the asynchronous method `fs.readFile` is invoked with an error-first callback function as its second parameter. This code causes both of the issues previously mentioned. An exception that isn't explicitly caught in the correct scope can crash the entire process (issue #1). Returning without ensuring the callback finishes means the http response will sometimes have an empty body (issue #2).
1931+
In the following example, the asynchronous method `fs.readFile` is invoked with an error-first callback function as its second parameter. This code causes both of the issues previously mentioned. An exception that isn't explicitly caught in the correct scope can crash the entire process (issue #1). Returning without ensuring the callback finishes means the http response sometimes has an empty body (issue #2).
19311932
19321933
# [JavaScript](#tab/javascript)
19331934

0 commit comments

Comments
 (0)