How to use Drag and Drop In Javascript
You can drag and drop the project folder of the JavaScript project to deploy it with Netlify by following the below steps.
Step 1: Create a project folder
Create a folder to put the project application inside that folder. It becomes easy to drag and drop the folder to build and make it deployed. Netlify has feature to analyse project and make that deployed.
Step 2: Create utility files
Create two files, One for HTML page(index.js) and one for JavaScript application code(script.js).
Step 3: A Sample JavaScript Application
It is a simple even-odd number checker application. It contains basic HTML code with a HTML form, label, input box, and a submit button. JavaScript code cotains logic to identify the number and check whether it is Even or Odd, and according to it, alerting the result on submit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Even or Odd Checker</title>
</head>
<body>
<h1>Even or Odd Checker</h1>
<form id="numberForm">
<label for="numberInput">
Enter a number:
</label>
<input type="number" id="numberInput" required>
<button type="submit">Submit</button>
</form>
<!-- Linking script file-->
<script src="script.js">
</script>
</body>
</html>
// JavaScript code to check if a number is even or odd
document.getElementById('numberForm')
.addEventListener('submit', function (event) {
event.preventDefault();
// Get the input value
const number =
parseInt(document.getElementById('numberInput').value);
// Check if the number is even or odd
if (number % 2 === 0) {
alert(number + ' is even.');
} else {
alert(number + ' is odd.');
}
});
Step 4: Open Netlify and login
Open Netlify, Login in it via signup or directly through github or gmail.
Step 5: Open sites tab
Go to Sites tab in the left sidebar just below the team overview tab.
Step 6: Navigate to ‘add new site’ and select Deploy manually.
Now, select the add new site tab in the right and then select the Deploy manually option from the dropdown.
Step 7: Drag and Drop the created project folder
After uploading project folder by drag and drop, Netlify build it and provide a live link of application. In this way, a JavaScript application can be deployed by just drag and drop. Below is the Output GIF.
Deployed project Output:
How to Deploy JavaScript Apps with Netlify ?
Deploying a JavaScript Application on Netlify is easy. You just need to run a few commands in your computer’s command prompt. Netlify works well with Git, so whenever you make changes to your code and push them to your Git repository, Netlify automatically updates your deployed app.
The below methods can be used to deploy JavaScript apps with Netlify:
Table of Content
- Using Drag and Drop
- Steps to deploy javascript application using Git repository
- Deployment using netlify-cli