Netlify command line tool for deploying and managing modern web applications on the Netlify platform
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Serverless function management including creation, local development, testing, and deployment of Netlify Functions with support for multiple languages and frameworks.
Create new serverless functions from templates with language and framework support.
/**
* Create a new serverless function from template
* Command: netlify functions:create [name] [options]
*/
interface FunctionCreateOptions {
/** Function name */
name?: string;
/** Template URL or repository */
url?: string;
/** Programming language (javascript, typescript, go, etc.) */
language?: string;
/** Disable network features during creation */
offline?: boolean;
}Usage Examples:
# Create function with interactive prompts
netlify functions:create
# Create named function
netlify functions:create hello-world
# Create function with specific language
netlify functions:create api-handler --language typescript
# Create function from custom template
netlify functions:create custom-func --url https://github.com/user/template
# Create function offline
netlify functions:create --offlineLocal development and testing tools for serverless functions.
/**
* Build functions locally
* Command: netlify functions:build [options]
*/
interface FunctionBuildOptions {
/** Functions directory */
functions?: string;
/** Source directory for functions */
src?: string;
}
/**
* Invoke/test functions locally
* Command: netlify functions:invoke [name] [options]
*/
interface FunctionInvokeOptions {
/** Function name to invoke */
name?: string;
/** Functions folder */
functions?: string;
/** Query string parameters */
querystring?: string;
/** POST payload data */
payload?: string;
/** Simulate Netlify Identity JWT token */
identity?: boolean;
/** Simulate unauthenticated request */
noIdentity?: boolean;
/** Netlify dev server port */
port?: number;
/** Disable network features */
offline?: boolean;
}
/**
* List local functions
* Command: netlify functions:list [options]
*/
interface FunctionListOptions {
/** Functions directory */
functions?: string;
/** Output as JSON */
json?: boolean;
}
/**
* Serve functions locally
* Command: netlify functions:serve [options]
*/
interface FunctionServeOptions {
/** Functions directory */
functions?: string;
/** Functions server port */
port?: number;
/** Disable network features */
offline?: boolean;
}Usage Examples:
# Build functions
netlify functions:build
# Build from custom source directory
netlify functions:build --src src/lambda --functions dist/functions
# List all functions
netlify functions:list
# List functions as JSON
netlify functions:list --json
# Invoke function locally
netlify functions:invoke hello-world
# Invoke with query parameters
netlify functions:invoke api --querystring "id=123&type=user"
# Invoke with POST data
netlify functions:invoke create-user --payload '{"name":"John","email":"john@example.com"}'
# Invoke with Identity simulation
netlify functions:invoke protected-route --identity
# Serve functions on custom port
netlify functions:serve --port 9999Supported languages and template system for function creation:
/**
* Supported function languages and runtimes
*/
type FunctionLanguage =
| 'javascript'
| 'typescript'
| 'go'
| 'rust'
| 'python';
/**
* Function template configuration
*/
interface FunctionTemplate {
/** Template name */
name: string;
/** Template description */
description: string;
/** Supported language */
language: FunctionLanguage;
/** Template repository URL */
url: string;
/** Required dependencies */
dependencies?: string[];
/** Environment variables needed */
envVars?: string[];
/** Template category */
category: 'api' | 'scheduled' | 'auth' | 'form' | 'webhook' | 'utility';
}
/**
* Popular built-in templates
*/
interface BuiltInTemplates {
'hello-world': FunctionTemplate;
'fetch-api': FunctionTemplate;
'send-email': FunctionTemplate;
'stripe-webhook': FunctionTemplate;
'auth-callback': FunctionTemplate;
'scheduled-task': FunctionTemplate;
'form-handler': FunctionTemplate;
'image-processing': FunctionTemplate;
'database-query': FunctionTemplate;
}Function configuration options and environment setup:
/**
* Function configuration in netlify.toml
*/
interface FunctionConfig {
/** Function-specific configuration */
functions: {
/** Functions directory */
directory: string;
/** Node.js version */
node_bundler?: 'esbuild' | 'zisi';
/** External node modules to include */
external_node_modules?: string[];
/** Included files pattern */
included_files?: string[];
/** Ignore patterns for function bundling */
ignore?: string[];
};
/** Individual function settings */
[functionName: string]: {
/** Runtime for this function */
runtime?: string;
/** Timeout in seconds (max 900) */
timeout?: number;
/** Memory allocation in MB */
memory?: number;
/** Environment variables */
environment?: Record<string, string>;
/** Schedule for background functions */
schedule?: string;
};
}
/**
* Function runtime environment
*/
interface FunctionEnvironment {
/** Netlify-provided environment variables */
netlifyVars: {
NETLIFY_DEV: string;
URL: string;
DEPLOY_URL: string;
CONTEXT: string;
BRANCH: string;
HEAD: string;
COMMIT_REF: string;
};
/** User-defined environment variables */
userVars: Record<string, string>;
/** Function-specific variables */
functionVars: Record<string, string>;
}Structure of event and context objects passed to functions:
/**
* Netlify Function event object
*/
interface NetlifyEvent {
/** HTTP method */
httpMethod: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
/** Request path */
path: string;
/** Query string parameters */
queryStringParameters: Record<string, string> | null;
/** Multi-value query string parameters */
multiValueQueryStringParameters: Record<string, string[]> | null;
/** Request headers */
headers: Record<string, string>;
/** Multi-value headers */
multiValueHeaders: Record<string, string[]>;
/** Request body (base64 encoded if binary) */
body: string | null;
/** Whether body is base64 encoded */
isBase64Encoded: boolean;
}
/**
* Netlify Function context object
*/
interface NetlifyContext {
/** Invocation ID */
awsRequestId: string;
/** Function name */
functionName: string;
/** Function version */
functionVersion: string;
/** Remaining time in milliseconds */
getRemainingTimeInMillis(): number;
/** CloudWatch log group */
logGroupName: string;
/** CloudWatch log stream */
logStreamName: string;
/** Memory limit in MB */
memoryLimitInMB: string;
/** Identity information if authenticated */
identity?: {
url: string;
token: string;
claims: Record<string, any>;
};
/** Client context for mobile apps */
clientContext?: {
client: {
installation_id: string;
app_title: string;
app_version_name: string;
app_version_code: string;
app_package_name: string;
};
env: Record<string, string>;
};
}
/**
* Function response format
*/
interface NetlifyResponse {
/** HTTP status code */
statusCode: number;
/** Response headers */
headers?: Record<string, string>;
/** Multi-value headers */
multiValueHeaders?: Record<string, string[]>;
/** Response body */
body: string;
/** Whether body is base64 encoded */
isBase64Encoded?: boolean;
}
/**
* Function handler signature
*/
type NetlifyHandler = (
event: NetlifyEvent,
context: NetlifyContext
) => Promise<NetlifyResponse> | NetlifyResponse;Different types of functions and common patterns:
/**
* API endpoint function pattern
*/
interface ApiFunction {
handler: NetlifyHandler;
/** HTTP methods this function handles */
methods: ('GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH')[];
/** Path pattern */
path: string;
/** Authentication required */
requiresAuth?: boolean;
/** Rate limiting configuration */
rateLimit?: {
windowMs: number;
maxRequests: number;
};
}
/**
* Background/scheduled function pattern
*/
interface BackgroundFunction {
handler: NetlifyHandler;
/** Cron schedule expression */
schedule: string;
/** Timezone for schedule */
timezone?: string;
/** Function description */
description: string;
}
/**
* Form handler function pattern
*/
interface FormHandler {
handler: NetlifyHandler;
/** Form name to handle */
formName: string;
/** Spam protection */
spamProtection?: boolean;
/** Success redirect URL */
successRedirect?: string;
/** Error redirect URL */
errorRedirect?: string;
}
/**
* Webhook function pattern
*/
interface WebhookFunction {
handler: NetlifyHandler;
/** Webhook provider */
provider: 'stripe' | 'github' | 'slack' | 'zapier' | 'custom';
/** Signature verification */
verifySignature?: boolean;
/** Webhook secret for verification */
secret?: string;
}Typical development workflow for Netlify Functions:
/**
* Function development lifecycle
*/
interface FunctionWorkflow {
/** Development phase */
development: {
/** Create function from template */
create: () => Promise<void>;
/** Local development server */
serve: () => Promise<void>;
/** Test function locally */
test: () => Promise<void>;
/** Debug with logs */
debug: () => Promise<void>;
};
/** Testing phase */
testing: {
/** Unit testing */
unit: () => Promise<void>;
/** Integration testing */
integration: () => Promise<void>;
/** Load testing */
load: () => Promise<void>;
};
/** Deployment phase */
deployment: {
/** Build for production */
build: () => Promise<void>;
/** Deploy to staging */
deployStaging: () => Promise<void>;
/** Deploy to production */
deployProduction: () => Promise<void>;
};
/** Monitoring phase */
monitoring: {
/** View function logs */
logs: () => Promise<void>;
/** Monitor performance */
performance: () => Promise<void>;
/** Error tracking */
errors: () => Promise<void>;
};
}Error handling patterns and debugging for functions:
/**
* Function error types
*/
interface FunctionError {
/** Error type */
type: 'syntax' | 'runtime' | 'timeout' | 'memory' | 'network' | 'user';
/** Error message */
message: string;
/** Stack trace */
stack?: string;
/** Request ID for debugging */
requestId: string;
/** Function name */
functionName: string;
/** Timestamp */
timestamp: Date;
}
/**
* Error response helpers
*/
interface ErrorHelpers {
/** Create 400 Bad Request response */
badRequest: (message: string) => NetlifyResponse;
/** Create 401 Unauthorized response */
unauthorized: (message?: string) => NetlifyResponse;
/** Create 403 Forbidden response */
forbidden: (message?: string) => NetlifyResponse;
/** Create 404 Not Found response */
notFound: (message?: string) => NetlifyResponse;
/** Create 500 Internal Server Error response */
serverError: (message?: string) => NetlifyResponse;
/** Create custom error response */
customError: (statusCode: number, message: string) => NetlifyResponse;
}