What is netlify-cli?
The netlify-cli package is a command-line tool that allows you to interact with Netlify services. It provides functionalities for deploying sites, managing DNS, handling functions, and more, directly from your terminal.
What are netlify-cli's main functionalities?
Deploy a site
This command deploys the site located in the './build' directory to Netlify. It is useful for quickly pushing updates to your site.
netlify deploy --dir=./build
Login to Netlify
This command opens a browser window to authenticate your Netlify account. It is the first step to using other Netlify CLI commands that require authentication.
netlify login
Create a new site
This command creates a new site on Netlify with the specified name 'my-new-site'. It is useful for setting up new projects quickly.
netlify sites:create --name=my-new-site
Manage DNS records
This command adds a DNS record to your Netlify-managed domain. It is useful for configuring custom domains and subdomains.
netlify dns:add --name=subdomain --type=A --value=127.0.0.1
Invoke serverless functions
This command invokes a serverless function named 'my-function' deployed on Netlify. It is useful for testing and debugging serverless functions.
netlify functions:invoke my-function
Other packages similar to netlify-cli
vercel
The Vercel CLI is a command-line tool for interacting with Vercel services. It offers similar functionalities to Netlify CLI, such as deploying sites, managing domains, and handling serverless functions. Vercel is known for its seamless integration with Next.js.
firebase-tools
The Firebase CLI provides a set of tools for managing Firebase projects and apps. It includes functionalities for deploying web apps, managing databases, and handling authentication. While it offers broader services compared to Netlify CLI, it is more focused on mobile and web app development.
aws-cli
The AWS CLI is a unified tool to manage AWS services. It provides extensive functionalities for deploying and managing cloud resources, including S3 for static site hosting and Lambda for serverless functions. It is more complex and feature-rich compared to Netlify CLI, catering to a wider range of cloud services.
Netlify CLI
The Netlify CLI tools lets you create, deploy, and delete new sites straight from your terminal.
Installation
To install the CLI tools:
npm install netlify-cli -g
Usage
Deploy a front-end project that lives in my-project
and builds to dist
directory:
cd my-project/
netlify deploy dist
Configuration and Authentication
The first time you use the netlify cli command you'll be asked to authenticate.
Your access token is stored in ~/.netlify/config
.
Netlify also stores a local .netlify
file in the folder where you run netlify deploy
from where the site_id
is stored.
Environments
You can easily setup different environments like staging
or production
. Just use the -e
flag:
netlify deploy dist -e production
Netlify creates different sites with each their own URL for each of your environments and keeps track of them in the .netlify
config file.