Local development with Netlify CLI (2024)

Contact

  • Forums
  • Contact support

Developer tools /CLI /

The Netlify CLI brings the functionality of your Netlify production environment directly to your local machine through the dev command. This CLI functionality is also referred to as Netlify Dev.

When you use Netlify Dev, the CLI provides a proxy server that includes edge logic for custom headers and redirects, environment variables, and Netlify Functions. It automatically detects tools and frameworks like Gatsby, Hugo, Eleventy, Next.js, and more to configure a local development server that mimics the Netlify production environment.

The sections below describe how to get started with Netlify Dev, how to start and share a live development server, how project detection and ports work, and how to customize the configuration.

You can also access the command reference for dev for more information.

# Get started with Netlify Dev

Before you begin, make sure you complete the following if you haven’t already:

  • Install the Netlify CLI.
  • Authenticate with an access token.
  • Link your local project to a Netlify siteID. To do this, set up continuous deployment with netlify init or link an existing Netlify site with netlify link.

To start a local development server for the build tool you’re using, run the following command from the root of your linked repository:

netlify dev

By default, Netlify Dev runs your project using the configuration and environment variables set for local development with the Netlify CLI. For environment variables, that means those with values set for dev or all deploy contexts. You can use the --context flag to run your project with a different deploy context’s settings and variables.

netlify dev --context production

Note that environment variables apply to all scopes when running netlify dev.

To run a shell command within the Netlify Dev environment, use exec:

netlify dev:exec YOUR_SHELL_COMMAND

You can run the following command to share your live development server over HTTPS. This creates a tunnel from your local development server over the internet and allows you to share the resulting URL with anyone anywhere in the world.

netlify dev --live

Anyone can access the resulting URL as long as the session is open.

# Project detection

Netlify Dev attempts to detect the site generator or build command that your project uses and run these on your behalf, while adding other development utilities. If you have a JavaScript project, it uses simple heuristics to search for the best package.json script to run for you, so you can use the full flexibility of npm scripts.

You also have the option to override framework detection, if needed.

Override framework detection

The number of frameworks that Netlify Dev can detect is growing but, if the framework you use is not yet supported, you can instruct Netlify Dev to run the project on your behalf. Configure your project’s build command, port, and publish directory with the [dev] block in your netlify.toml file.

# sample dev block in the toml# note: each of these fields are optional and should only be used if you need an override[dev] command = "yarn start" # Command to start your dev server targetPort = 3000 # The port for your application server, framework, or site generator port = 8888 # The port that the Netlify Dev will be accessible on publish = "dist" # If you use a _redirect file, provide the path to your static content folder

If the CLI detects your project incorrectly or detects multiple frameworks, you can specify a framework option to test only one detector against your project.

[dev] framework = "create-react-app" # or "#static" to force a static server

Possible values of framework:

  • #auto (default) to check all available frameworks.
  • The ID for one of the available frameworks, as specified in the .json file for that framework in the Netlify Build repository.
  • #static for a static file server
  • #custom to use the command option to run an app server and targetPort option to connect to it

# Project ports

When you use Netlify Dev, you may encounter a few different ports — especially if your project uses a static site generator that has its own dev server, like Gatsby. Keep the following in mind when working with Netlify Dev:

  • If your project uses a framework that we can detect, Netlify Dev will use the framework’s conventional ports, so you don’t have to supply them yourself. If multiple detectors match your project, we’ll ask you to choose.
  • If your site generator runs on a specific port, such as port 8000, you need to specify the port when you run netlify dev. Netlify Dev will connect to that port and route requests successfully to the site generator along with the rest of the local Netlify environment.
  • If you use an unrecognized site generator or framework, or have a server you want Netlify Dev to connect to, you need to specify the port when you run netlify dev.

To confirm which port to use for local development with Netlify Dev, search for this box in your console output:

 ┌──────────────────────────────────────────────────────────────┐ │ │ │ [Netlify Dev] Server now ready on http://localhost:8888 │ │ │ └──────────────────────────────────────────────────────────────┘

# Configuration

Netlify Dev works without configuration for the majority of users, but you can customize Netlify Dev settings in the [dev] section of the Netlify configuration file. The following sections outline some common configuration options.

For a full list of the available properties, refer to the Netlify Dev section of our file-based configuration doc.

# Run an https server for local development

By default, netlify dev starts an HTTP server. If you require HTTPS, you can configure a certificate and key file foruse by netlify dev in your netlify.toml:

[dev] [dev.https] certFile = "cert.pem" keyFile = "key.pem"

Self-signed certificates require extra configuration

If you’re using a self-signed certificate, you might need to configure your browser to accept it when running on localhost. To enable this setting for Chrome, visit chrome://flags/#allow-insecure-localhost in your browser.

# Specify custom ports for Netlify Dev

Netlify Dev allows you to specify custom ports using the following parameters as flags or in a Netlify configuration file (netlify.toml):

  • targetPort: the port for your application server, framework, or site generator
  • port: the port for the Netlify Dev server that you will open in the browser

Netlify Dev tries to acquire these ports but if they are already in use by another application, it will throw an error and let you know.

[dev] targetPort = 3000 port = 8888

# More Netlify Dev resources

  • Command reference for dev
  • Configuration properties for Netlify Dev in netlify.toml
  • Use Netlify CLI with monorepos
  • Manage Functions with Netlify CLI

Get started with Netlify CLI Manage functions with Netlify CLI

Did you find this doc useful?

Your feedback helps us improve our docs.

Local development with Netlify CLI (2024)
Top Articles
Achivr Visb Bill Pymnt
Montclair Radiology Patient Portal
Feet.girl01
Jeff Liebler Wife
Keck Healthstream
Becu Turbotax Discount Code
Deshaun Watson suspension ruling live updates: Latest on settlement with NFL, reactions
Care Guide for Platy Fish – Feeding, Breeding, and Tank Mates
Myzmanim Edison Nj
Eggy Car Unblocked - Chrome Web Store
Minor Additions To The Bill Crossword
Comparing Each Tacoma Generation, Which is Best?
Myjohnshopkins Mychart
The Obscure Spring Watch Online Free
Bigbug Rotten Tomatoes
Craigslist Apartments In Philly
Yellow Kitchen Curtains Walmart
24 Hour Pharmacy St Louis Mo
P.o. Box 30924 Salt Lake City Ut
Can You Put Elvie Stride Parts In Sterilizer
Cara In Creekmaw Code
Apria Healthcare - 26 Reviews - Sacramento, CA
Warren County Skyward
Sky Park Stl Coupon
Garagesalefinder Com
Cavender’s 50th Anniversary: How the Cavender Family Built — and Continues to Grow — a Western Wear Empire Using Common Sense values
Free 120 Step 2 Correlation
Https //Pay.instamed.com/Tricore
Proctor Motors In Lampasas
Infinity Pool Showtimes Near Cinemark 14 Chico
Fast X Showtimes Near Evo Cinemas Creekside 14
Tnt Tony Superfantastic
King of Battle and Blood
Family Leisure Sale
O'reilly's Los Banos
Unblocked Games 66E
Myhr North Memorial
Hourly Pay At Dick's Sporting Goods
Babbychula
The Whale Showtimes Near Cinépolis Vista
Rage Of Harrogath Bugged
MAXSUN Terminator Z790M D5 ICE Motherboard Review
Owen Roeder Tim Dillon
Cvs Pharmacy Tb Test
Joftens Notes Skyrim
Foolproof Module 6 Test Answers
The Menu Showtimes Near Regal Edwards Ontario Mountain Village
Brokaw 24 Hour Fitness
Umn Biology
Espn Ppr Fantasy Football Rankings
Christian Publishers Outlet Rivergate
Two Soyjaks Pointing Png
Latest Posts
Article information

Author: Lakeisha Bayer VM

Last Updated:

Views: 6454

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Lakeisha Bayer VM

Birthday: 1997-10-17

Address: Suite 835 34136 Adrian Mountains, Floydton, UT 81036

Phone: +3571527672278

Job: Manufacturing Agent

Hobby: Skimboarding, Photography, Roller skating, Knife making, Paintball, Embroidery, Gunsmithing

Introduction: My name is Lakeisha Bayer VM, I am a brainy, kind, enchanting, healthy, lovely, clean, witty person who loves writing and wants to share my knowledge and understanding with you.