Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Assess and migrate workloads from AWS, GCP, or other clouds to Azure services.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/services/functions/runtimes/typescript.md
1# TypeScript — Azure Functions v4 Triggers & Bindings23> **Model**: Node.js v4 programming model (TypeScript). Same as JavaScript v4 with type annotations.4> **NO** `function.json` files.5> Import: `import { app, HttpRequest, HttpResponseInit, InvocationContext, input, output } from '@azure/functions';`67TypeScript uses the same `app.*()` registration as JavaScript. See [javascript.md](javascript.md) for all trigger/binding patterns. Below are TypeScript-specific type signatures.89## HTTP Trigger1011```typescript12import { app, HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions';1314app.http('httpFunction', {15methods: ['GET', 'POST'],16authLevel: 'anonymous',17handler: async (request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> => {18const name = request.query.get('name') || (await request.text());19return { body: `Hello, ${name}!` };20}21});22```2324## Blob Storage Trigger2526```typescript27import { app, InvocationContext } from '@azure/functions';2829app.storageBlob('blobTrigger', {30path: 'samples-workitems/{name}',31connection: 'AzureWebJobsStorage',32source: 'EventGrid',33handler: async (blob: Buffer, context: InvocationContext): Promise<void> => {34context.log(`Blob: ${context.triggerMetadata.name}, Size: ${blob.length}`);35}36});37```3839## Queue Storage Trigger4041```typescript42app.storageQueue('queueTrigger', {43queueName: 'myqueue-items',44connection: 'AzureWebJobsStorage',45handler: async (queueItem: unknown, context: InvocationContext): Promise<void> => {46context.log('Queue item:', queueItem);47}48});49```5051## Timer Trigger5253```typescript54import { app, InvocationContext, Timer } from '@azure/functions';5556app.timer('timerFunction', {57schedule: '0 */5 * * * *',58handler: async (myTimer: Timer, context: InvocationContext): Promise<void> => {59context.log('Timer fired at:', myTimer.scheduleStatus?.last);60}61});62```6364## Cosmos DB Trigger6566```typescript67app.cosmosDB('cosmosDBTrigger', {68connectionStringSetting: 'CosmosDBConnection',69databaseName: 'mydb',70containerName: 'mycontainer',71createLeaseContainerIfNotExists: true,72handler: async (documents: unknown[], context: InvocationContext): Promise<void> => {73documents.forEach(doc => context.log('Changed doc:', doc));74}75});76```7778## Service Bus Queue Trigger7980```typescript81app.serviceBusQueue('sbQueueTrigger', {82queueName: 'myqueue',83connection: 'ServiceBusConnection',84handler: async (message: unknown, context: InvocationContext): Promise<void> => {85context.log('Message:', message);86}87});88```8990## Event Grid Trigger9192```typescript93import { app, EventGridEvent, InvocationContext } from '@azure/functions';9495app.eventGrid('eventGridTrigger', {96handler: async (event: EventGridEvent, context: InvocationContext): Promise<void> => {97context.log('Event:', event.subject, event.eventType);98}99});100```101102## Event Hubs Trigger103104```typescript105app.eventHub('eventHubTrigger', {106eventHubName: 'myeventhub',107connection: 'EventHubConnection',108cardinality: 'many',109handler: async (events: unknown[], context: InvocationContext): Promise<void> => {110events.forEach(event => context.log('Event:', event));111}112});113```114115## Input/Output Bindings116117TypeScript uses the same `input.*()` and `output.*()` helpers as JavaScript. See [javascript.md](javascript.md) for full binding examples — all patterns are identical with added type annotations.118119> Full reference: [Azure Functions TypeScript developer guide](https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=typescript)120