スキル一覧に戻る
yuma-722

azure-functions-nodejs

by yuma-722

0🍴 0📅 2026年1月19日
GitHubで見るManusで実行

SKILL.md


name: azure-functions-nodejs description: Create and configure Node.js Azure Functions projects using command-line tools. Use when users want to (1) create a new Azure Functions project with Node.js/TypeScript, (2) add HTTP trigger functions or other trigger types, (3) scaffold Azure Functions templates, (4) migrate from programming model v3 to v4, or (5) set up local Azure Functions development environment with proper configuration files.

Azure Functions Node.js Template Creator

Overview

Create Node.js Azure Functions projects using command-line tools (Azure Functions Core Tools). This skill guides you through project initialization, function creation, and configuration for both JavaScript and TypeScript with the v4 programming model.

Prerequisites

Before creating an Azure Functions project, verify these requirements:

  • Node.js 18+ (Node.js 22.x, 20.x, and 18.x are supported)
  • Azure Functions Core Tools v4.0.5382+ installed
  • @azure/functions npm package v4.0.0+
  • Azure Functions Runtime v4.25+
  • For TypeScript: TypeScript v4+

Quick Start: Create a New Azure Functions Project

Step 1: Initialize the Project

Create a new Azure Functions project in the current directory:

JavaScript:

func init --worker-runtime node --language javascript --model V4

TypeScript:

func init --worker-runtime node --language typescript --model V4

Note: The --model V4 option explicitly specifies the v4 programming model.

This command creates:

  • host.json - Functions host configuration
  • local.settings.json - Local development settings
  • package.json - Node.js project file
  • .gitignore - Git ignore rules
  • For TypeScript: tsconfig.json - TypeScript configuration

Step 2: Add a Function

Add an HTTP trigger function to the project:

func new --name HttpExample --template "HTTP trigger" --authlevel "function"

Available parameters:

  • --name: Function name (unique within the project)
  • --template: Template type (e.g., "HTTP trigger", "Timer trigger", "Queue trigger")
  • --authlevel: Authorization level ("anonymous", "function", or "admin")

Step 3: Configure package.json

After initialization, update the package.json to set the entry point:

For single file structure:

{
  "main": "src/index.js"
}

For multiple function files:

{
  "main": "src/functions/*.js"
}

For TypeScript (compiled output):

{
  "main": "dist/src/index.js"
}

Step 4: Install Dependencies

Install the required npm packages:

npm install @azure/functions

For TypeScript projects, ensure dev dependencies are installed:

npm install

Programming Model v4 Structure

JavaScript Example

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}!` };
    },
});

TypeScript Example

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,
});

Function Trigger Types

Use the app object to register different trigger types:

  • app.http() - HTTP trigger
  • app.timer() - Timer trigger
  • app.storageBlob() - Blob storage trigger
  • app.storageQueue() - Queue storage trigger
  • app.cosmosDB() - Cosmos DB trigger
  • app.eventHub() - Event Hub trigger
  • app.serviceBusTopic() - Service Bus topic trigger
  • app.serviceBusQueue() - Service Bus queue trigger

Common Configuration Options

HTTP Trigger Options

app.http('functionName', {
    methods: ['GET', 'POST'],           // HTTP methods
    authLevel: 'anonymous',              // 'anonymous', 'function', or 'admin'
    route: 'custom/route/{id}',         // Custom route (optional)
    handler: handlerFunction
});

Timer Trigger Options

app.timer('timerFunction', {
    schedule: '0 */5 * * * *',          // NCRONTAB expression
    handler: handlerFunction
});

Running Locally

Start the local development server:

func start

For TypeScript projects, compile first:

npm run build
func start

Or for auto-compilation during development:

npm start

Workflow for Adding Functions to Existing Projects

When a user requests to add a new Azure Function to an existing project:

  1. Verify Azure Functions Core Tools is installed

    func --version
    
  2. Navigate to the project root (where host.json exists)

  3. Use func new to create the function

    func new --name <FunctionName> --template "<TriggerType>" --authlevel "<AuthLevel>"
    
  4. After template creation, modify the generated code to match the user's requirements:

    • Update the handler logic
    • Modify trigger configuration
    • Add input/output bindings as needed
    • Update routes or timing as required
  5. For v4 programming model, ensure the function is properly registered using the app object

  6. Test locally with func start before deployment

Migration from v3 to v4

For detailed migration guidance, see references/v3-to-v4-migration.md.

Key changes:

  • Switch argument order: (request, context) instead of (context, request)
  • Use return value for output instead of context.res
  • Functions defined in code, not in function.json files
  • Import from @azure/functions package required

Directory Structure Recommendations

Single file structure (simple projects):

my-functions-app/
├── src/
│   └── index.js          # All functions defined here
├── host.json
├── local.settings.json
└── package.json

Multiple file structure (recommended for complex projects):

my-functions-app/
├── src/
│   └── functions/
│       ├── httpTrigger.js
│       ├── timerTrigger.js
│       └── queueTrigger.js
├── test/
│   └── functions/        # Optional: test files
│       └── httpTrigger.test.js
├── host.json
├── local.settings.json
└── package.json

For TypeScript projects (compiled output):

my-functions-app/
├── dist/
│   └── src/
│       └── functions/
│           └── *.js      # Compiled JavaScript files
├── src/
│   └── functions/
│       └── *.ts          # TypeScript source files
├── host.json
├── local.settings.json
├── package.json
└── tsconfig.json

Resources

Advanced Features (v4 Programming Model)

SDK Types

SDK types provide direct access to Azure SDK clients for enhanced functionality:

  • Blob Storage: Access BlobClient, BlockBlobClient for advanced blob operations
  • Service Bus: Access ServiceBusClient for message handling and properties
  • See trigger-types.md for detailed examples

HTTP Streams (Preview)

Enable streaming responses for scenarios like Server-Sent Events or large file downloads:

  • Requires Node.js 20.x+ and Azure Functions Runtime 4.25+
  • Enable via host.json: "enableHttpStream": true
  • See trigger-types.md for examples

Hooks

Execute code before and after function invocations:

  • App-level hooks: Apply to all functions in the app
  • Invocation-level hooks: Apply to specific function executions
  • Use for logging, authentication, or cleanup tasks

Example:

const { app } = require('@azure/functions');

// App-level hook
app.hook.appStart(async (context) => {
    context.log('App is starting...');
});

// Invocation-level hook
app.hook.preInvocation(async (context) => {
    context.log(`Invoking function: ${context.functionName}`);
});

references/

  • v3-to-v4-migration.md - Detailed migration guide from programming model v3 to v4
  • trigger-types.md - Complete reference of all available trigger types and their configurations

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です