### Example Monorepo Directory Structure Source: https://docs.netlify.com/build/configure-builds/monorepos Illustrates a typical monorepo setup with multiple applications and a component library, suitable for hosting on Netlify. ```bash / ├─ apps/ │ ├─ app-1/ │ │ ├─ package.json │ │ ├─ netlify.toml │ │ ├─ ...app-1-source-files │ ├─ app-2/ │ │ ├─ package.json │ │ ├─ netlify.toml │ │ ├─ ...app-2-source-files │ ├─ other-packages/ │ ├─ component-library/ │ │ ├─ package.json │ │ ├─ ...component-library-source-files │ ├─ package.json ``` -------------------------------- ### Initialize Netlify Database with CLI Source: https://docs.netlify.com/build/data-and-storage/netlify-database/getting-started Use the `netlify database init` command for an interactive setup. It installs necessary packages, lets you choose a query style (Drizzle ORM or direct SQL), scaffolds migrations, and optionally seeds the database. ```bash netlify database init ``` -------------------------------- ### Install Netlify TanStack Start Vite Plugin Source: https://docs.netlify.com/build/frameworks/framework-setup-guides/tanstack-start Install the Netlify Vite plugin for TanStack Start to enable seamless deployment on Netlify. ```bash npm install -D @netlify/vite-plugin-tanstack-start ``` -------------------------------- ### Install @netlify/next Source: https://docs.netlify.com/build/frameworks/framework-setup-guides/nextjs/legacy-runtime/middleware Install the @netlify/next library in your project using npm. ```bash npm install @netlify/next ``` -------------------------------- ### Fetching All Sites Source: https://docs.netlify.com/api-and-cli-guides/api-guides/get-started-with-api This example demonstrates how to retrieve a list of all sites you have access to by making a GET request to the /sites endpoint. ```APIDOC ## GET /sites ### Description Retrieves a list of all sites associated with the authenticated user or team. ### Method GET ### Endpoint https://api.netlify.com/api/v1/sites ### Parameters None ### Request Example ```bash curl -H "User-Agent: MyApp (YOUR_NAME@EXAMPLE.COM)" \ -H "Authorization: Bearer YOUR_OAUTH2_ACCESS_TOKEN" \ https://api.netlify.com/api/v1/sites ``` ### Response #### Success Response (200) An array of site objects. #### Response Example ```json [ { "id": "some-site-id", "name": "my-netlify-site", "domain": "my-netlify-site.netlify.app" } ] ``` ``` -------------------------------- ### Install Netlify Database Package Source: https://docs.netlify.com/build/data-and-storage/netlify-database/getting-started Install the `@netlify/database` package using npm. This is a required step for manual setup and for using Netlify Database in your project. ```bash npm install @netlify/database ``` -------------------------------- ### Install @netlify/cache Source: https://docs.netlify.com/build/caching/cache-api Install the @netlify/cache module using npm. ```bash npm install @netlify/cache ``` -------------------------------- ### Install a local plugin in netlify.toml Source: https://docs.netlify.com/extend/develop-and-share/develop-build-plugins Specify the absolute path to your local plugin folder in the 'package' field of netlify.toml. The path must start with '.' or '/'. ```toml # netlify.toml [[plugins]] package = "/plugins/netlify-plugin-hello-world" ``` -------------------------------- ### Install and Configure a Build Plugin Source: https://docs.netlify.com/build/configure-builds/file-based-configuration Add build plugins to your Netlify project by specifying the package name and any necessary inputs in the [[plugins]] section of netlify.toml. This example shows how to configure inputs for a plugin. ```toml [[plugins]] package = "netlify-plugin-check-output-for-puppy-references" [plugins.inputs] breeds = ["pomeranian", "chihuahua", "bulldog"] ``` -------------------------------- ### Deploy to Netlify Button URL Example Source: https://docs.netlify.com/deploy/create-deploys This is an example of the URL structure for the 'Deploy to Netlify' button, specifying a GitHub repository to clone. ```txt https://app.netlify.com/start/deploy?repository=https://github.com/netlify/netlify-statuskit ``` -------------------------------- ### Get General CLI Help Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli Run 'netlify help' to get usage tips and learn about available commands within the Netlify CLI. ```bash netlify help ``` -------------------------------- ### Initialize Netlify CLI for manual setup Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli Use this command for manual setup with GitLab, Bitbucket, Azure DevOps, or if you prefer limited, repository-only access on GitHub. It prompts you to set deploy settings and provides a deploy/access key and webhook URL. ```bash netlify init --manual ``` -------------------------------- ### Install Gatsby Adapter for Netlify Source: https://docs.netlify.com/build/frameworks/framework-setup-guides/gatsby Use this command to manually install the Gatsby adapter for Netlify if automatic installation does not occur. ```shell npm install gatsby-adapter-netlify ``` -------------------------------- ### Install Netlify CLI Source: https://docs.netlify.com/build/edge-functions/get-started Install the Netlify CLI globally to manage your Netlify projects and test edge functions locally. ```bash npm install netlify-cli -g ``` -------------------------------- ### Start Netlify Dev Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/local-development Run this command from the root of your linked repository to start a local development server. It uses configuration and environment variables set for local development. ```bash netlify dev ``` -------------------------------- ### Install All Netlify Skills Source: https://docs.netlify.com/llms.txt Installs all available Netlify Skills, which provide AI agents with context and tools for building on Netlify platform primitives. Use the --yes flag to skip confirmation prompts. ```bash npx skills add netlify/context-and-tools --skill '*' --yes ``` -------------------------------- ### Install Netlify Adapter for Astro Source: https://docs.netlify.com/build/frameworks/framework-setup-guides/astro Run this command in your Astro project's directory to install the Netlify Adapter and automatically update your configuration file. ```shell npx astro add netlify ``` -------------------------------- ### Install @netlify/async-workloads with npm Source: https://docs.netlify.com/build/async-workloads/writing-workloads Install the Async Workloads module using npm. This provides the necessary functionality and types for TypeScript projects. ```bash npm install @netlify/async-workloads ``` -------------------------------- ### Set Build Command for TanStack Start Versions Before 1.121.0 Source: https://docs.netlify.com/build/frameworks/framework-setup-guides/tanstack-start For TanStack Start versions before 1.121.0, use 'vinxi build' as the build command. ```bash vinxi build ``` -------------------------------- ### Install @netlify/functions Package Source: https://docs.netlify.com/build/configure-builds/on-demand-builders Add the @netlify/functions package as a development dependency to your site. ```bash npm install -D @netlify/functions ``` -------------------------------- ### Install Netlify CLI Source: https://docs.netlify.com/llms.txt Installs the Netlify Command Line Interface globally using npm. This is a prerequisite for many Netlify development and deployment tasks. ```bash npm install -g netlify-cli ``` -------------------------------- ### Install Netlify Blobs Source: https://docs.netlify.com/build/data-and-storage/netlify-blobs Install the Netlify Blobs module using npm. This is required before using the API in functions, edge functions, or build plugins. ```bash npm install @netlify/blobs ``` -------------------------------- ### Install Netlify Agent Skills Source: https://docs.netlify.com/build/build-with-ai/agent-setup-guides/agent-setup-overview Use this command to install all Netlify agent skills for your project or agent. This command adds the specified skill to your agent. ```bash npx skills add netlify/context-and-tools --skill "*" --yes ``` -------------------------------- ### Example .env file for production Source: https://docs.netlify.com/build/environment-variables/get-started Environment variables in a .env file are formatted as key-value pairs, with each variable on a new line. This example shows a production .env file. ```dotenv YOUR_API_KEY=a production secret NODE_VERSION=16 NODE_ENV=production ``` -------------------------------- ### Get Hooks for a Site Source: https://docs.netlify.com/api-and-cli-guides/api-guides/get-started-with-api Retrieves a list of all configured hooks for a specific site. Use this to view existing notification setups. ```json [ { "id": "5636b7a00d61eec2d6001004", "site_id": "0d3a9d2f-ef94-4380-93df-27ee400e2048", "type": "email", "event": "submission_created", "data": { "email": "test@example.com" }, "created_at": "2015-10-20T21:51:51Z", "updated_at": "2015-10-20T21:51:51Z" } ] ``` -------------------------------- ### Sample netlify.toml configuration Source: https://docs.netlify.com/build/configure-builds/file-based-configuration This example demonstrates how to combine multiple settings in a single netlify.toml file, including build settings, plugins, and different deploy contexts. ```toml # Settings for the [build] key are global and are applied to # all deploy contexts unless overridden by a context-specific setting. [build] # Directory where the build system installs dependencies # and runs your build. Store your package.json, .nvmrc, etc here. # If not set, defaults to the root directory. base = "project/" # Directory that contains the deploy-ready HTML files and # assets generated by the build. This is an absolute path relative # to the base directory, which is the root by default (/). # This sample publishes the directory located at the absolute # path "root/project/build-output" publish = "build-output/" # Default build command. command = "echo 'default context'" [[plugins]] # Installs the Lighthouse Build Plugin for all deploy contexts package = "@netlify/plugin-lighthouse" # Production context: all deploys from the Production branch # set in your site's Branches settings in the UI will inherit # these settings. You can define environment variables # here but we recommend using the Netlify UI for sensitive # values to keep them out of your source repository. [context.production] publish = "output/" command = "make publish" environment = { NODE_VERSION = "14.15.3" } # Deploy Preview context: all deploys generated from # a pull/merge request will inherit these settings. [context.deploy-preview] publish = "dist/" # Here is an example of how to define context-specific # environment variables. To avoid committing sensitive # values to public source repositories, set variables # with the Netlify UI, CLI, or API instead. [context.deploy-preview.environment] NOT_PRIVATE_ITEM = "not so secret" # Branch Deploy context: all deploys that are not from # a pull/merge request or from the Production branch # will inherit these settings. [context.branch-deploy] command = "echo branch" [context.branch-deploy.environment] NODE_ENV = "development" # Dev context: environment variables set here # are available for local development environments # run using Netlify Dev. These values can be # overwritten on branches that have a more specific # branch context configured. [context.dev.environment] NODE_ENV = "development" # Specific branch context: all deploys from # this specific branch will inherit these settings. [context.staging] # "staging" is a branch name command = "echo 'staging'" base = "staging" # For contexts of branches with special characters, # enclose the branch name with quotes. [context."feat/branch"] command = "echo 'special branch'" base = "branch" # Redirects and headers are GLOBAL for all builds - they do not # get scoped to contexts no matter where you define them in the file. # For context-specific rules, use _headers or _redirects files, # which are PER-DEPLOY. # A basic redirect rule [[redirects]] from = "/*" to = "/blog/:splat" # A redirect rule with many of the supported properties [[redirects]] from = "/old-path" to = "/new-path" # The default HTTP status code is 301, but you can # define a different one. status = 302 # By default, redirects won't be applied if there's a file # with the same path as the one defined in the `from` property. # Setting `force` to `true` will make the redirect rule # take precedence over any existing files. force = true # Redirect from /old-path?id=123 to /new-path. # Each combination of query params needs to be # defined in a separate [[redirects]] block. # More information at https://docs.netlify.com/manage/routing/redirects/redirect-options/#query-parameters query = {id = ":id"} # Redirect based on conditions including browser language, # geolocation, identity role, and/or cookie presence. conditions = {Language = ["en"], Country = ["US"]} # Sign each request with a value defined in an environment variable signed = "API_SIGNATURE_TOKEN" # You can also define custom headers within your redirects blocks. [redirects.headers] X-From = "Netlify" X-Api-Key = "some-api-key-string" # Redirects for role-based access control don't use the 'to' property. [[redirects]] from = "/gated-path" status = 200 conditions = {Role = ["admin"]} force = true # The following redirect is intended for use with most SPAs # that handle routing internally. [[redirects]] from = "/*" to = "/index.html" status = 200 [[headers]] # Define which paths this specific [[headers]] block will cover. for = "/*" [headers.values] X-Frame-Options = "DENY" Content-Security-Policy = "frame-ancestors https://www.facebook.com" # Multi-value headers are expressed with multi-line strings. cache-control = ''' max-age=0, no-cache, no-store, must-revalidate''' ``` -------------------------------- ### Store Level Strong Consistency Source: https://docs.netlify.com/build/data-and-storage/netlify-blobs Configures a store with strong consistency at the store level. This example demonstrates setting and getting a blob with guaranteed consistency. ```typescript export default async (req: Request, context: Context) => { const store = getStore({ name: "animals", consistency: "strong" }); await store.set("dog", "🐶"); // This is a strongly-consistent read. const dog = await store.get("dog"); return new Response(dog); }; ``` -------------------------------- ### Initialize Netlify CLI for automated setup Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli Run this command from your local repository to connect it to Netlify for continuous deployment. It will prompt you to log in to GitHub and create necessary access tokens and webhooks. ```bash netlify init ``` -------------------------------- ### Set Up Environment Variables Source: https://docs.netlify.com/build/frameworks/framework-setup-guides/hydrogen Copy the example environment file to .env to configure your Hydrogen project for local development. ```bash cp .env.example .env ``` -------------------------------- ### Configure Image Transformation Redirects (_redirects) Source: https://docs.netlify.com/build/image-cdn/overview Define redirects to apply consistent image transformation parameters across multiple images. This example sets a redirect for paths starting with `/transform-small/*` to apply a width and height of 50px. ```netlify-config /transform-small/* /.netlify/images?url=/:splat&w=50&h=50 200 ``` -------------------------------- ### Create Project with Netlify CLI Source: https://docs.netlify.com/build/data-and-storage/netlify-database/getting-started Use the Netlify CLI to create a new project with Netlify Database pre-configured. This command initiates an AI-driven setup process. ```bash netlify create "An app for managing my music collection. For each record, I want to store the title, artist name, year and medium (CD or vinyl). I want to be able to filter entries and search by any of these fields" ``` -------------------------------- ### Create a Netlify project from a prompt Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli Generate, deploy, and download a new Netlify project from a natural language description. This command uses Agent Runners to automate the build and deployment process. ```bash netlify create "a landing page for a SaaS product with a waitlist signup" ``` -------------------------------- ### Link an existing local project Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli If you have already cloned a repository manually, use this command instead of `netlify init` or `netlify init --manual` to link your local project to a Netlify site. ```bash netlify link ``` -------------------------------- ### JSON Metadata Example Source: https://docs.netlify.com/build/data-and-storage/netlify-blobs Example of valid JSON metadata that can be attached to blobs. ```json { "name": "Jerry" } ``` -------------------------------- ### Install Gatsby Plugin for Netlify (npm) Source: https://docs.netlify.com/build/frameworks/framework-setup-guides/gatsby Install the gatsby-plugin-netlify package as a development dependency using npm. ```shell npm install -D gatsby-plugin-netlify ``` -------------------------------- ### Install Express Dependencies Source: https://docs.netlify.com/build/frameworks/framework-setup-guides/express Install necessary dependencies for an Express project. Exclude `@netlify/functions` and `@types/express` if using JavaScript. ```bash npm i express serverless-http @netlify/functions @types/express ``` -------------------------------- ### Get Help for a Specific Command Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli To get more information about a specific command, run 'help' followed by the command name. ```bash netlify help deploy ``` -------------------------------- ### Run Netlify Deploy Command Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli Initiates a manual deploy from your local project directory. The first run prompts for site selection or creation. ```bash netlify deploy ``` -------------------------------- ### Get Sites Source: https://docs.netlify.com/api-and-cli-guides/api-guides/get-started-with-api Retrieves a list of all sites accessible to the authenticated user. This endpoint is useful for getting an overview of your deployed projects. ```APIDOC ## GET /api/v1/sites ### Description Retrieves all sites you have access to. ### Method GET ### Endpoint /api/v1/sites ### Response #### Success Response (200) - **id** (string) - The unique identifier for the site. - **premium** (boolean) - Indicates if the site is a premium feature. - **claimed** (boolean) - Indicates if the site has been claimed. - **name** (string) - The name of the site. - **custom_domain** (string) - The custom domain associated with the site. - **url** (string) - The public URL of the site. - **admin_url** (string) - The Netlify admin URL for the site. - **screenshot_url** (string) - URL for a screenshot of the site, or null. - **created_at** (string) - The timestamp when the site was created. - **updated_at** (string) - The timestamp when the site was last updated. - **user_id** (string) - The ID of the user who owns the site. ### Response Example ```json [ { "id": "3970e0fe-8564-4903-9a55-c5f8de49fb8b", "premium": false, "claimed": true, "name": "synergy", "custom_domain": "www.example.com", "url": "http://www.example.com", "admin_url": "https://api.netlify.com/sites/synergy", "screenshot_url": null, "created_at": "2013-09-17T05:13:08Z", "updated_at": "2013-09-17T05:13:19Z", "user_id": "51f60d2d5803545326000005" } ] ``` ``` -------------------------------- ### Generate TanStack Starter App with CLI Source: https://docs.netlify.com/build/frameworks/framework-setup-guides/tanstack-start Use this command to generate a new TanStack starter app with the file router template and Netlify add-ons. ```bash npx create-tsrouter-app@latest --template file-router --add-ons tanchat,netlify ``` -------------------------------- ### Configure TanStack Start for Versions Before 1.121.0 Source: https://docs.netlify.com/build/frameworks/framework-setup-guides/tanstack-start For TanStack Start versions prior to 1.121.0, configure the server preset in app.config.ts. ```typescript import { defineConfig } from '@tanstack/react-start/config' export default defineConfig({ server: { preset: 'netlify', }, }) ``` -------------------------------- ### Get an individual environment variable's value Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli Use `env:get` to retrieve the value of a specific environment variable. By default, it gets values for local development contexts (`dev` or `all`). Use `--context` or `--scope` to retrieve values from other contexts or scopes. ```bash netlify env:get API_KEY ``` ```bash netlify env:get API_KEY --context production ``` -------------------------------- ### Run Hydrogen App Locally Source: https://docs.netlify.com/build/frameworks/framework-setup-guides/hydrogen Start your Hydrogen development server to preview and customize your storefront locally. ```bash npm run dev ``` -------------------------------- ### Install @netlify/async-workloads with yarn Source: https://docs.netlify.com/build/async-workloads/writing-workloads Install the Async Workloads module using yarn. This provides the necessary functionality and types for TypeScript projects. ```bash yarn add @netlify/async-workloads ``` -------------------------------- ### Install @netlify/async-workloads with pnpm Source: https://docs.netlify.com/build/async-workloads/writing-workloads Install the Async Workloads module using pnpm. This provides the necessary functionality and types for TypeScript projects. ```bash pnpm add @netlify/async-workloads ``` -------------------------------- ### Create Site and Deploy Simultaneously Using ZIP Source: https://docs.netlify.com/api-and-cli-guides/api-guides/get-started-with-api This cURL command creates a new Netlify site and deploys it from a ZIP file in a single request. It's useful for initial site setup. ```bash curl -H "Content-Type: application/zip" \ -H "Authorization: Bearer YOUR_OAUTH2_ACCESS_TOKEN" \ --data-binary "@website.zip" \ https://api.netlify.com/api/v1/sites ``` -------------------------------- ### Deploy using a ZIP file Source: https://docs.netlify.com/api-and-cli-guides/api-guides/get-started-with-api You can deploy your site by uploading a ZIP file. This method requires setting the Content-Type to application/zip and providing the ZIP file as the request body. ```APIDOC ## POST /api/v1/sites/{site_id}/deploys ### Description Creates a new deploy for a specific site using a ZIP file. ### Method POST ### Endpoint /api/v1/sites/{site_id}/deploys ### Parameters #### Path Parameters - **site_id** (string) - Required - The ID of the site to deploy to. #### Request Body - **Content-Type**: application/zip - Required - Specifies the content type as a ZIP file. - **ZIP file**: binary - Required - The ZIP file containing the site's files. ### Request Example ```bash curl -H "Content-Type: application/zip" \ -H "Authorization: Bearer YOUR_OAUTH2_ACCESS_TOKEN" \ --data-binary "@website.zip" \ https://api.netlify.com/api/v1/sites/mysite.netlify.app/deploys ``` ``` -------------------------------- ### Install npm Dependencies Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli Installs Node.js dependencies required for deploying TypeScript or JavaScript functions. Run this in any folder containing a package.json file. ```sh npm install ``` -------------------------------- ### Perform a Production Deploy Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli Deploys the site to the main production URL. Use the --prod flag or its shorthand -p. ```bash netlify deploy --prod ``` -------------------------------- ### Example JavaScript-Rendered Form with AJAX Submission Source: https://docs.netlify.com/manage/forms/setup A complete example of a React form component that uses the handleSubmit function for AJAX submission to Netlify. ```jsx return (
); ``` -------------------------------- ### Hello World Builder Example in JavaScript Source: https://docs.netlify.com/build/configure-builds/on-demand-builders A basic builder function that returns an HTML page with a 'Hello World' message. This response will be cached. ```javascript const { builder } = require("@netlify/functions") async function handler(event, context) { return { statusCode: 200, headers: { "Content-Type": "text/html", }, body: ` Hello World `, }; } exports.handler = builder(handler); ``` -------------------------------- ### Create a new site and deploy from a ZIP file Source: https://docs.netlify.com/api-and-cli-guides/api-guides/get-started-with-api This endpoint allows you to create a new site and deploy it simultaneously using a ZIP file, saving an additional HTTP request. ```APIDOC ## POST /api/v1/sites ### Description Creates a new site and deploys it from a ZIP file in a single request. ### Method POST ### Endpoint /api/v1/sites ### Parameters #### Request Body - **Content-Type**: application/zip - Required - Specifies the content type as a ZIP file. - **ZIP file**: binary - Required - The ZIP file containing the site's files. ### Request Example ```bash curl -H "Content-Type: application/zip" \ -H "Authorization: Bearer YOUR_OAUTH2_ACCESS_TOKEN" \ --data-binary "@website.zip" \ https://api.netlify.com/api/v1/sites ``` ``` -------------------------------- ### Install Vite Plugin for Netlify Functions Source: https://docs.netlify.com/build/functions/get-started Install the Netlify Vite plugin to enable local development of Netlify Functions within Vite-based frameworks. ```bash npm install @netlify/vite-plugin ``` -------------------------------- ### Check Netlify CLI Version and Info Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli Verifies the installation of Netlify CLI and displays basic information about the tool. ```bash netlify ``` -------------------------------- ### Install Yarn Dependencies Source: https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli Installs Node.js dependencies using Yarn for deploying TypeScript or JavaScript functions. Run this in any folder containing a package.json file. ```sh yarn ``` -------------------------------- ### Configure Deploy to Netlify button templates Source: https://docs.netlify.com/build/configure-builds/file-based-configuration Use the `[template]` section to provide template-specific configuration for Deploy to Netlify buttons. This includes setting up incoming webhooks and environment variables. ```toml [template] incoming-hooks = ["Contentful"] [template.environment] SECRET_TOKEN = "change me for your secret token" CUSTOM_LOGO = "set the url to your custom logo here" ``` -------------------------------- ### Initiate Deploy with File Digest Source: https://docs.netlify.com/api-and-cli-guides/api-guides/get-started-with-api Start a new deploy for a specific site using the file digest method. This method requires providing a list of files and their SHA1 hashes. ```bash POST /api/v1/sites/{site_id}/deploys ```