Netlify command line tool for deploying and managing modern web applications on the Netlify platform
npx @tessl/cli install tessl/npm-netlify-cli@23.5.0Netlify CLI is a command-line interface tool that enables developers to interact with Netlify's platform for modern web development and deployment. It provides comprehensive commands for managing sites, deploying applications, running local development servers, handling serverless functions, managing environment variables, and integrating with Netlify's edge functions and build system.
npm install -g netlify-cliThe CLI provides both command-line binaries and programmatic APIs:
Command-line binaries:
netlify --help
ntl --help # short aliasProgrammatic API (Node.js):
import { NetlifyAPI, methods } from "netlify-cli";For CommonJS:
const { NetlifyAPI, methods } = require("netlify-cli");Quick start:
# Install globally
npm install -g netlify-cli
# Login to Netlify
netlify login
# Initialize a project
netlify init
# Start local development
netlify dev
# Deploy to production
netlify deploy --prodCommon workflow:
# Clone a project with the CLI
netlify clone [repository]
# Link to existing Netlify site
netlify link
# Set environment variables
netlify env:set API_KEY "your-api-key"
# Run local development server with Netlify features
netlify dev --port 3000
# Deploy with build
netlify deploy --build --prodThe Netlify CLI is built on several key components:
Core project and site management functionality for creating, linking, and configuring Netlify projects.
// Command: netlify sites:create
interface SiteCreateOptions {
name?: string; // Project name (max 63 chars)
accountSlug?: string; // Account slug
withCi?: boolean; // Initialize CI hooks
manual?: boolean; // Force manual CI setup
disableLinking?: boolean; // Create without linking
}
// Command: netlify link
interface LinkOptions {
id?: string; // Project ID to link
name?: string; // Project name to link
gitRemoteName?: string; // Git remote name
}Local development server with Netlify's proxy, redirect rules, and serverless function support.
// Command: netlify dev
interface DevOptions {
command?: string; // Command to run
context?: string; // Deploy context (default: dev)
port?: number; // Netlify dev port
targetPort?: number; // Target app server port
framework?: string; // Framework to use (#auto for detection)
dir?: string; // Static files directory
functions?: string; // Functions folder
live?: string | boolean; // Start public live session
geo?: 'cache' | 'mock' | 'update'; // Geolocation mode
country?: string; // Two-letter country code
offline?: boolean; // Disable network features
}Build and deployment functionality with support for various contexts and deployment options.
// Command: netlify deploy
interface DeployOptions {
dir?: string; // Directory to deploy
functions?: string; // Functions folder
prod?: boolean; // Deploy to production
prodIfUnlocked?: boolean; // Deploy to production if unlocked
alias?: string; // Deployment alias (max 37 chars)
message?: string; // Deploy log message
json?: boolean; // Output as JSON
timeout?: number; // Deployment timeout
build?: boolean; // Run build command
createSite?: string; // Create new site during deployment
}Environment variable management with context support for different deployment environments.
// Command: netlify env:set
interface EnvSetOptions {
context?: string[]; // Deploy contexts (multiple)
scope?: ('builds' | 'functions' | 'post-processing' | 'runtime' | 'any')[]; // Variable scopes
secret?: boolean; // Mark as secret variable
json?: boolean; // Output as JSON
}
// Command: netlify env:get
interface EnvGetOptions {
context?: string; // Deploy context (default: dev)
scope?: 'builds' | 'functions' | 'post-processing' | 'runtime' | 'any'; // Variable scope
json?: boolean; // Output as JSON
}Serverless function management including creation, testing, and deployment of Netlify Functions.
// Command: netlify functions:create
interface FunctionCreateOptions {
name?: string; // Function name
url?: string; // Template URL
language?: string; // Function language
offline?: boolean; // Disable network features
}
// Command: netlify functions:invoke
interface FunctionInvokeOptions {
name?: string; // Function name
functions?: string; // Functions folder
querystring?: string; // Query string
payload?: string; // POST payload
identity?: boolean; // Simulate Netlify Identity JWT
noIdentity?: boolean; // Simulate unauthenticated request
port?: number; // Netlify dev port
}Object storage management for Netlify Blobs with CRUD operations and metadata handling.
// Command: netlify blobs:set
interface BlobSetOptions {
input?: string; // Read data from filesystem path
}
// Command: netlify blobs:get
interface BlobGetOptions {
output?: string; // Output path to save blob data
}
// Command: netlify blobs:list
interface BlobListOptions {
directories?: boolean; // Treat keys with '/' as directories
prefix?: string; // Filter entries by prefix
json?: boolean; // Output as JSON
}Local and remote build functionality with context support and offline capabilities.
// Command: netlify build
interface BuildOptions {
context?: string; // Deploy context (default: production)
dry?: boolean; // Show instructions without running
offline?: boolean; // Disable network features
}
// Command: netlify serve
interface ServeOptions {
context?: string; // Deploy context
port?: number; // Server port
dir?: string; // Static files directory
functions?: string; // Functions folder
geo?: 'cache' | 'mock' | 'update'; // Geolocation mode
}Authentication management and team switching functionality for multi-account workflows.
// Command: netlify login
interface LoginOptions {
new?: boolean; // Login to new account
}PostgreSQL database provisioning and management for modern web applications.
// Command: netlify database:init
interface DatabaseInitOptions {
assumeNo?: boolean; // Non-interactive setup
boilerplate?: 'drizzle'; // Type of boilerplate to add
noBoilerplate?: boolean; // Don't add boilerplate code
overwrite?: boolean; // Overwrite existing files
}
// Command: netlify database:status
interface DatabaseStatusOptions {
/** No additional options */
}Clone Git repositories with optional framework filtering for quick project setup.
// Command: netlify clone [repository] [directory]
interface CloneOptions {
filter?: string; // Filter template results by framework
}Watch for project changes and deploy automatically for continuous deployment workflows.
// Command: netlify watch
interface WatchOptions {
dir?: string; // Directory to deploy
functions?: string; // Functions folder
}Stream and view logs from builds and serverless functions for debugging and monitoring.
// Command: netlify logs:deploy (alias: logs:build)
interface LogsDeployOptions {
/** No additional options */
}
// Command: netlify logs:function [functionName]
interface LogsFunctionOptions {
level?: ('trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal')[]; // Log levels to stream
}Interactive setup and configuration templates for different frameworks and use cases.
// Command: netlify recipes
interface RecipesOptions {
/** Interactive recipe selection */
}Execute commands in the development environment context with full access to environment variables.
// Command: netlify dev-exec <command...>
interface DevExecOptions {
context?: string; // Deploy context for environment variables
}Open project resources and admin interfaces in browser for quick access.
// Command: netlify open:admin
interface OpenAdminOptions {
/** No additional options */
}
// Command: netlify open:site
interface OpenSiteOptions {
/** No additional options */
}Direct access to Netlify's REST API for advanced automation and custom integrations.
// Command: netlify api
interface ApiOptions {
data?: string; // JSON data payload for API call
list?: boolean; // List all available API methods
}Generate shell completion scripts for improved command-line productivity.
// Command: netlify completion
interface CompletionOptions {
shell?: 'bash' | 'zsh' | 'fish' | 'powershell'; // Target shell
}All commands support these global options:
interface GlobalOptions {
telemetryDisable?: boolean; // Disable usage telemetry
telemetryEnable?: boolean; // Enable usage telemetry
version?: boolean; // Show version information
verbose?: boolean; // Show detailed environment information
auth?: string; // Authentication token
debug?: boolean; // Enable debug mode
cwd?: string; // Working directory (hidden but functional)
httpProxy?: string; // HTTP proxy configuration (hidden)
silent?: boolean; // Silence output (hidden)
filter?: string; // Monorepo package selection
}The CLI supports context-aware operations for different deployment environments:
production - Production environmentdeploy-preview - Deploy preview environment (pull requests)branch-deploy - Branch deployment environmentdev - Development environment (local)branch:branch-name - Specific branch contexttype DeployContext = 'production' | 'deploy-preview' | 'branch-deploy' | 'dev' | `branch:${string}`;
type VariableScope = 'builds' | 'functions' | 'post-processing' | 'runtime' | 'any';
type GeoMode = 'cache' | 'mock' | 'update';
type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
interface NetlifyConfig {
build?: {
command?: string;
publish?: string;
functions?: string;
};
redirects?: Array<{
from: string;
to: string;
status?: number;
}>;
headers?: Array<{
for: string;
values: Record<string, string>;
}>;
}The CLI also provides programmatic access to Netlify's API:
/**
* Netlify API client for programmatic access
* Re-exported from @netlify/api package
*/
class NetlifyAPI {
constructor(token?: string, options?: ApiOptions);
// Site management
listSites(): Promise<Site[]>;
getSite(siteId: string): Promise<Site>;
createSite(params: CreateSiteParams): Promise<Site>;
deleteSite(siteId: string): Promise<void>;
// Deploy management
listDeploys(siteId: string): Promise<Deploy[]>;
getDeploy(deployId: string): Promise<Deploy>;
createDeploy(siteId: string, params: CreateDeployParams): Promise<Deploy>;
// Function management
listFunctions(siteId: string): Promise<Function[]>;
// ... additional API methods
}
/**
* API method definitions
* Re-exported from @netlify/api package
*/
const methods: {
listSites: ApiMethod;
getSite: ApiMethod;
createSite: ApiMethod;
// ... additional method definitions
};