You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-reference-node.md
+80Lines changed: 80 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1422,6 +1422,86 @@ The response can be set in several ways:
1422
1422
1423
1423
::: zone-end
1424
1424
1425
+
## Hooks
1426
+
1427
+
::: zone pivot="nodejs-model-v3"
1428
+
1429
+
Hooks aren't supported in the v3 model. [Upgrade to the v4 model](./functions-node-upgrade-v4.md) to use hooks.
1430
+
1431
+
::: zone-end
1432
+
::: zone pivot="nodejs-model-v4"
1433
+
1434
+
Use a hook to execute code at different points in the Azure Functions lifecycle. Hooks are executed in the order they're registered and can be registered from any file in your app. There are currently two scopes of hooks, "app" level and "invocation" level.
1435
+
1436
+
### Invocation hooks
1437
+
1438
+
Invocation hooks are executed once per invocation of your function, either before in a `preInvocation` hook or after in a `postInvocation` hook. By default your hook executes for all trigger types, but you can also filter by type. The following example shows how to register an invocation hook and filter by trigger type:
The first argument to the hook handler is a context object specific to that hook type.
1451
+
1452
+
The `PreInvocationContext` object has the following properties:
1453
+
1454
+
| Property | Description |
1455
+
| --- | --- |
1456
+
| **`inputs`** | The arguments passed to the invocation. |
1457
+
| **`functionHandler`** | The function handler for the invocation. Changes to this value affect the function itself. |
1458
+
| **`invocationContext`** | The [invocation context](#invocation-context) object passed to the function. |
1459
+
| **`hookData`** | The recommended place to store and share data between hooks in the same scope. You should use a unique property name so that it doesn't conflict with other hooks' data. |
1460
+
1461
+
The `PostInvocationContext` object has the following properties:
1462
+
1463
+
| Property | Description |
1464
+
| --- | --- |
1465
+
| **`inputs`** | The arguments passed to the invocation. |
1466
+
| **`result`** | The result of the function. Changes to this value affect the overall result of the function. |
1467
+
| **`error`** | The error thrown by the function, or null/undefined if there's no error. Changes to this value affect the overall result of the function. |
1468
+
| **`invocationContext`** | The [invocation context](#invocation-context) object passed to the function. |
1469
+
| **`hookData`** | The recommended place to store and share data between hooks in the same scope. You should use a unique property name so that it doesn't conflict with other hooks' data. |
1470
+
1471
+
### App hooks
1472
+
1473
+
App hooks are executed once per instance of your app, either during startup in an `appStart` hook or during termination in an `appTerminate` hook. App terminate hooks have a limited time to execute and don't execute in all scenarios.
1474
+
1475
+
The Azure Functions runtime currently [doesn't support](https://github.com/Azure/azure-functions-host/issues/8222) context logging outside of an invocation. Use the Application Insights [npm package](https://www.npmjs.com/package/applicationinsights) to log data during app level hooks.
The first argument to the hook handler is a context object specific to that hook type.
1490
+
1491
+
The `AppStartContext` object has the following properties:
1492
+
1493
+
| Property | Description |
1494
+
| --- | --- |
1495
+
| **`hookData`** | The recommended place to store and share data between hooks in the same scope. You should use a unique property name so that it doesn't conflict with other hooks' data. |
1496
+
1497
+
The `AppTerminateContext` object has the following properties:
1498
+
1499
+
| Property | Description |
1500
+
| --- | --- |
1501
+
| **`hookData`** | The recommended place to store and share data between hooks in the same scope. You should use a unique property name so that it doesn't conflict with other hooks' data. |
1502
+
1503
+
::: zone-end
1504
+
1425
1505
## Scaling and concurrency
1426
1506
1427
1507
By default, Azure Functions automatically monitors the load on your application and creates more host instances for Node.js as needed. Azure Functions uses built-in (not user configurable) thresholds for different trigger types to decide when to add instances, such as the age of messages and queue size for QueueTrigger. For more information, see [How the Consumption and Premium plans work](event-driven-scaling.md).
0 commit comments