Netlify is a hosting platform that allows you to deploy static websites and front end applications (React, Angular, Vue). The free account offers a lot, but you can also get a pro account.
Netlify makes it simple to get set up and start deploying stuff by allowing you to login in through and deploy repositories from your Github, Gitlab, or Bitbucket account.
Deploying From the Browser
First, login to Netlify with one of these three version control platforms. Then, choose “New Site from Git” and on the next page choose your platform again. It will show you all of your repositories from your account. Choose the branch you want to deploy from (I recommend creating a separate deployment branch so you can still push to your master branch without it affecting your website).
Netlify CLI
Netlify also offers a CLI (command-line interface) tool that you can use to make deployments, etc. as opposed to using their simple online platform.
First, cd
into your project directory and type this command: sudo
npm i -g netlify-cli
. Then, type netlify deploy
. In your browser, Netlify CLI will ask for permission to authorize Netlify on your behalf; choose to authorize this. Then, close the window and return back to your Terminal. Answer the prompts on whether it’s a new site and which path to deploy from and you’re done! Netlify will generate a default domain for you to view your site on the Web.
Deploying a React App
We will be deploying the React App from Terminal. Make sure you already have the Netlify CLI installed globally on your system.
First, if you haven’t done so already, you want to build out your static assets using this command in your project directory: npm run build
. This will put everything into a build folder. So, now if you ls
your directory, you will see a folder called build.
Now you want to run the netlify deploy
command (assuming you’ve already installed the CLI). Choose the build folder we created above as the path to deploy. That’s it! You’re site is deployed.
Using a Custom Domain
On the Netlify platform, choose the project which you’d like to give a custom domain. Then, press the “Domain Settings” button. Then press “Add Custom Domain.” Type in the custom domain name you’d like to use (after you’ve already boughten it, of course) and press “Add Domain.” In the Domain Registrar you use, go do any additional configuration / setup you need.
Netlify Forms
Netlify has a built-in form service called Netlify Forms that allows you to manage forms and submissions without any server-side code or JavaScript.
It’s extremely easy to implement this service in your HTML form. Just add the netlify
attribute to any form and everything gets wired up automatically. Their bots find your forms by inspecting the HTML of your site before its published.
<form name="contact" netlify>
<label>Name <input type="text" name="name" /></label>
<button type="submit">Submit</button>
</form>