This article is an excerpt from the book, Web Development on Netlify, by Ekene Eze. This book is a comprehensive guide to deploying and scaling frontend web applications on Netlify. With hands-on instructions and real-world examples, this book takes you from setting up a Netlify account and deploying web apps to optimizing performance.
Deploying a web application can sometimes be a daunting task, especially with the various methods and tools available. In this article, we'll explore two straightforward deployment methods offered by Netlify: the drag-and-drop method, which is beginner-friendly and ideal for static sites, and the Netlify CLI (Netlify Dev) method, which provides greater control for developers who prefer using the command line.
We will discuss two deployment methods in this chapter: the drag-and-drop method and the Netlify CLI (Netlify Dev) m ethod. A third method, the Git-based method, was covered in the Connecting to a Git repository section in Chapter 1.
The drag-and-drop deployment method is the most straightforward and beginner-friendly way to deploy a web application on Netlify. Th is method is suitable for static websites or applications that do not require complex build processes.
To deploy your web application on Netlify using the drag-and-drop method, follow these steps:
1. Organize your project files and ensure your project’s index.html file is in the root folder so that Netlify can easily find it and build your site from there:
Figure 2.1 – Netlify drop sample structure
2. Visit netlify.com and sign in or create an account.
3. On your Netlify dashboard, locate the Sites section. Drag and drop your project folder into the designated area. Netlify will automatically upload your files, create a new site, deploy it, and assign a randomly generated URL. You can click on the generated URL to view your live site.
4. Optionally, configure your site. To configure your site’s settings, such as adding a custom domain or enabling SSL, click the Site settings button. We will discuss these configuration options in greater detail later, in the Configuring settings and o options section.
The Netlify CLI deployment method offers greater control over the deployment process for developers who prefer using the command line. Follow these steps to deploy your web applications to Netlify using the Netlify CLI:
1. Install the Netlify CLI globally on your computer using npm:
npm install -g netlify-cli
2. Run the following command to authenticate your Netlify account:
netlify login
Your browser will open so that you can authorize access to your Netlify account.
3. Navigate to your project folder in the command line and run the following command to initialize a new Netlify site:
netlify init
4. You will be prompted to choose between connecting an existing Git repository or creating a new site without a Git repository. Choose the option that best suits your needs. Connecting to a Git repository enables continuous deployment.
4. If your project requires specifi c build settings, open the automatically created netlify.toml fi le in your project’s root directory and confi gure the settings accordingly. Here’s an example:
toml
[build]
command = "npm run build"
publish = "dist"
This configuration would run the npm run build command and deploy the dist folder as the publish directory.
Run the following command in your project directory to deploy your site:
netlify deploy
By default, this command creates a draft deployment. Preview the draft by visiting the generated URL.
7. If you are satisfied with the draft deployment, run the following command for a production deployment:
netlify deploy --prod
This will create a production deployment with a randomly generated URL.
8. Visit your Netlify dashboard to view your live site or configure your site’s settings, such as adding a custom domain or enabling SSL. This step will be covered in more detail in the Configuring settings and options section of this chapter.
Refer to Chapter 1 for the Git-based deployment process.
Need help choosing a pattern for your needs? Here’s a tabular comparison of the three deployment patterns offered by Netlify: Git-based deployments, CLI deployments, and drag-and-drop:
Deployment Pattern | When to Choose | Key Benefits |
Git-based deployments | Ideal for collaborative development | Version control, automated builds, code review |
CLI deployments | Ideal for advanced automation scenarios | Scripted deployments, custom workflows |
Drag-and-drop deployments | Ideal for simple, non-technical users | User-friendly, visual interface, quick deployments |
Table – Choosing a deployment pattern
Now, let’s discuss when each deployment pattern is ideal and why:
The choice of deployment pattern depends on your specific needs and your technical expertise. Git-based deployments are suitable for collaborative development, CLI deployments offer advanced automation capabilities, and drag-and-drop deployments are ideal for non-technical users seeking a simple interface. Understanding the strengths and trade-offs of each pattern will help you select the most appropriate deployment approach for your project.
Choosing the right deployment method is crucial for the success and efficiency of your web application. Whether you opt for the simplicity of the drag-and-drop method, the command-line control of the Netlify CLI, or the collaborative advantages of Git-based deployments, each approach has its unique strengths. The drag-and-drop method offers a quick and easy solution for non-technical users, while the CLI method provides advanced automation capabilities for more complex scenarios. Git-based deployments, on the other hand, are perfect for teams working in a collaborative environment with a need for version control. By understanding these methods and their respective benefits, you can confidently deploy your web application on Netlify using the approach that best aligns with your goals and expertise.
Ekene Eze is a highly experienced Developer Advocate with over five years of professional experience in leading DevRel teams across multiple organizations. As a former member of the Developer Experience team at Netlify, he played a key role in helping numerous companies integrate and effectively utilize the Netlify platform. As a well-regarded speaker, he is dedicated to sharing his knowledge and expertise with the wider development community through a variety of mediums, including blog posts, video tutorials, live streams, and podcasts. Currently serving as the Director of Developer Relations at Abridged Inc, the author brings a wealth of experience and expertise to this comprehensive guide on scaling web applications with Netlify.