Azure Functions Node.js Programming Model
Branch | Status | Support level | Node.js Versions |
---|---|---|---|
v4.x |
|
Preview | 18 |
v3.x (default) |
|
GA (Recommended) | 18, 16, 14 |
Install
npm install @azure/functions@preview
Documentation
- Azure Functions JavaScript Developer Guide
- Upgrade guide from v3 to v4
- Create your first TypeScript function
- Create your first JavaScript function
Considerations
- During preview, the v4 model requires you to set the app setting
AzureWebJobsFeatureFlags
toEnableWorkerIndexing
. For more information, see Enable v4 programming model. - The Node.js "programming model" shouldn't be confused with the Azure Functions "runtime".
- Programming model: Defines how you author your code and is specific to JavaScript and TypeScript.
- Runtime: Defines underlying behavior of Azure Functions and is shared across all languages.
- The programming model version is strictly tied to the version of the
@azure/functions
npm package, and is versioned independently of the runtime. Both the runtime and the programming model use "4" as their latest major version, but that is purely a coincidence.
Usage
TypeScript
import { app, HttpRequest, HttpResponseInit, InvocationContext } from "@azure/functions";
export async function httpTrigger1(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
context.log(`Http function processed request for url "${request.url}"`);
const name = request.query.get('name') || await request.text() || 'world';
return { body: `Hello, ${name}!` };
};
app.http('httpTrigger1', {
methods: ['GET', 'POST'],
authLevel: 'anonymous',
handler: httpTrigger1
});
JavaScript
const { app } = require('@azure/functions');
app.http('httpTrigger1', {
methods: ['GET', 'POST'],
authLevel: 'anonymous',
handler: async (request, context) => {
context.log(`Http function processed request for url "${request.url}"`);
const name = request.query.get('name') || await request.text() || 'world';
return { body: `Hello, ${name}!` };
}
});
Contributing
- Clone the repository locally and open in VS Code
- Run "Extensions: Show Recommended Extensions" from the command palette and install all extensions listed under "Workspace Recommendations"
- Run
npm install
- Run
npm run build
- Run
npm link
- Create or open a local function app to test with
- In the local function app:
- Run
npm link @azure/functions
. This will point your app to the local repository for the@azure/functions
package - Add the following settings to your "local.settings.json" file or configure them directly as environment variables
-
languageWorkers__node__arguments
:--inspect
💡 Tip: Setlogging__logLevel__Worker
todebug
if you want to view worker-specific logs in the output offunc start
-
- Start the app (i.e. run
func start
or press F5)
- Run
- Back in the framework repository, press F5 and select the process for your running function app
- Before you submit a PR, run
npm test
and fix any issues. If you want to debug the tests, switch your launch profile in VS Code to "Launch Unit Tests" and press F5.
Code of Conduct
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Contributing to type definitions
The type definitions are located in the types
folder. Please make sure to update the tests in ./test/types/index.test.ts
as well.