
azure-functions-nodejs
by yuma-722
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 configurationlocal.settings.json- Local development settingspackage.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 triggerapp.timer()- Timer triggerapp.storageBlob()- Blob storage triggerapp.storageQueue()- Queue storage triggerapp.cosmosDB()- Cosmos DB triggerapp.eventHub()- Event Hub triggerapp.serviceBusTopic()- Service Bus topic triggerapp.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:
-
Verify Azure Functions Core Tools is installed
func --version -
Navigate to the project root (where
host.jsonexists) -
Use
func newto create the functionfunc new --name <FunctionName> --template "<TriggerType>" --authlevel "<AuthLevel>" -
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
-
For v4 programming model, ensure the function is properly registered using the
appobject -
Test locally with
func startbefore 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.jsonfiles - Import from
@azure/functionspackage 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,BlockBlobClientfor advanced blob operations - Service Bus: Access
ServiceBusClientfor 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 v4trigger-types.md- Complete reference of all available trigger types and their configurations
Score
Total Score
Based on repository quality metrics
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
Reviews
Reviews coming soon