Skip to content

Commit 40b1ad3

Browse files
authored
Update v4 readme (#69)
1 parent 98bfb92 commit 40b1ad3

File tree

4 files changed

+50
-38
lines changed

4 files changed

+50
-38
lines changed

README.md

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Azure Functions Node.js Framework
1+
# Azure Functions Node.js Programming Model
22

33
|Branch|Status|Support level|Node.js Versions|
44
|---|---|---|---|
@@ -7,51 +7,64 @@
77

88
## Install
99

10-
```
11-
npm install @azure/functions
10+
```bash
11+
npm install @azure/functions@preview
1212
```
1313

14-
## Usage
14+
## Documentation
15+
16+
- [Azure Functions JavaScript Developer Guide](https://learn.microsoft.com/azure/azure-functions/functions-reference-node?pivots=nodejs-model-v4)
17+
- [Upgrade guide from v3 to v4](https://learn.microsoft.com/azure/azure-functions/functions-node-upgrade-v4)
18+
- [Create your first TypeScript function](https://docs.microsoft.com/azure/azure-functions/create-first-function-vs-code-typescript?pivots=nodejs-model-v4)
19+
- [Create your first JavaScript function](https://docs.microsoft.com/azure/azure-functions/create-first-function-vs-code-node?pivots=nodejs-model-v4)
20+
21+
## Considerations
1522

16-
_**UPDATE**_: **See here for important information on v4 of the Azure Functions Node.js Framework: https://aka.ms/AzFuncNodeV4**
23+
- During preview, the v4 model requires you to set the app setting `AzureWebJobsFeatureFlags` to `EnableWorkerIndexing`. For more information, see [Enable v4 programming model](https://learn.microsoft.com/azure/azure-functions/functions-reference-node?pivots=nodejs-model-v4#enable-v4-programming-model).
24+
- The Node.js "programming model" shouldn't be confused with the Azure Functions "runtime".
25+
- _**Programming model**_: Defines how you author your code and is specific to JavaScript and TypeScript.
26+
- _**Runtime**_: Defines underlying behavior of Azure Functions and is shared across all languages.
27+
- 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 versioned independently of the [runtime](https://learn.microsoft.com/azure/azure-functions/functions-versions?pivots=programming-language-javascript). Both the runtime and the programming model use "4" as their latest major version, but that is purely a coincidence.
1728

18-
Prior to version 3.5.0, this package only contained TypeScript type definitions. Starting with version 3.5.0 it _also_ contains the underlying Azure Functions Framework for Node.js. This framework package is included by default in [v4.x of the Azure Functions runtime](https://docs.microsoft.com/azure/azure-functions/functions-versions?pivots=programming-language-javascript), meaning you do _not_ need to include the package in your app. However, there may be cases where you want a specific version of the package, so you can override the default shipped in Azure with the below steps.
29+
## Usage
1930

20-
### TypeScript:
31+
### TypeScript
2132

22-
For a full tutorial, see [how to create your first TypeScript function](https://docs.microsoft.com/azure/azure-functions/create-first-function-vs-code-typescript).
33+
```typescript
34+
import { app, HttpRequest, HttpResponseInit, InvocationContext } from "@azure/functions";
2335

24-
1. Specify a main entrypoint in your package.json
25-
```json
26-
"main": "dist/src/index.js"
27-
```
28-
2. Add the following code to your entrypoint file (e.g. `src/index.ts`):
29-
```typescript
30-
import * as func from '@azure/functions';
36+
export async function httpTrigger1(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
37+
context.log(`Http function processed request for url "${request.url}"`);
3138

32-
func.setup();
33-
```
39+
const name = request.query.get('name') || await request.text() || 'world';
3440

35-
**IMPORTANT NOTE**: If you only want this package for the TypeScript type definitions, you may list this package in the "devDependencies" section of your package.json. If you are overriding the default shipped in Azure as described above, the package must be listed in the production "dependencies" section of your package.json.
41+
return { body: `Hello, ${name}!` };
42+
};
3643

37-
For more documentation, see the [TypeScript developer guide](https://docs.microsoft.com/azure/azure-functions/functions-reference-node#typescript).
44+
app.http('httpTrigger1', {
45+
methods: ['GET', 'POST'],
46+
authLevel: 'anonymous',
47+
handler: httpTrigger1
48+
});
49+
```
3850

3951
### JavaScript
4052

41-
For a full tutorial, see [how to create your first JavaScript function](https://docs.microsoft.com/azure/azure-functions/create-first-function-vs-code-node).
53+
```javascript
54+
const { app } = require('@azure/functions');
4255

43-
1. Specify a main entrypoint in your package.json
44-
```json
45-
"main": "src/index.js"
46-
```
47-
2. Add the following code to your entrypoint file:
48-
```javascript
49-
const func = require('@azure/functions');
50-
51-
func.setup();
52-
```
56+
app.http('httpTrigger1', {
57+
methods: ['GET', 'POST'],
58+
authLevel: 'anonymous',
59+
handler: async (request, context) => {
60+
context.log(`Http function processed request for url "${request.url}"`);
5361

54-
For more documentation, see the [JavaScript developer guide](https://docs.microsoft.com/azure/azure-functions/functions-reference-node).
62+
const name = request.query.get('name') || await request.text() || 'world';
63+
64+
return { body: `Hello, ${name}!` };
65+
}
66+
});
67+
```
5568

5669
## Contributing
5770

@@ -62,8 +75,7 @@ For more documentation, see the [JavaScript developer guide](https://docs.micros
6275
- Run `npm link`
6376
- Create or open a local function app to test with
6477
- In the local function app:
65-
- Make sure you are calling `func.setup()` somewhere in your app, as described above in the "Usage" section
66-
- Run `npm link @azure/functions`. This will point your app to the local repository for the framework package
78+
- Run `npm link @azure/functions`. This will point your app to the local repository for the `@azure/functions` package
6779
- Add the following settings to your "local.settings.json" file or configure them directly as environment variables
6880
- `languageWorkers__node__arguments`: `--inspect`
6981
> 💡 Tip: Set `logging__logLevel__Worker` to `debug` if you want to view worker-specific logs in the output of `func start`
@@ -77,4 +89,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
7789

7890
### Contributing to type definitions
7991

80-
The type definitions are located in the `types` folder. Please make sure to update the tests in `./test/types/index.test.ts` as well.
92+
The type definitions are located in the `types` folder. Please make sure to update the tests in `./test/types/index.test.ts` as well.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/functions",
3-
"version": "4.0.0-alpha.8",
3+
"version": "4.0.0-alpha.9",
44
"description": "Microsoft Azure Functions NodeJS Framework",
55
"keywords": [
66
"azure",

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
export const version = '4.0.0-alpha.8';
4+
export const version = '4.0.0-alpha.9';
55

66
export const returnBindingKey = '$return';

0 commit comments

Comments
 (0)