399 words
2 minutes
How to Create a Blog Using Astro and Cloudflare

In this guide, you’ll learn how to set up a static blog using Astro and host it on Cloudflare.

Cloudflare offers free static hosting with no limit on traffic.

Astro is a modern JavaScript framework and popular static site generator.

Requirements#

For this guide, you will need:

To make sure you have git and node installed, run in a terminal window:

Terminal window
git --version
node --version

You should see version numbers if they are installed correctly.

Project setup#

Open a terminal window and run the following command to start the Astro setup:

Terminal window
npm create astro@latest

Enter a name for the new project (for example ./astro-blog). A new folder will be created for it.

Select the blog template and “Yes” to installing dependencies and initializing a git repository.

If everything worked correctly, you should see the following message:

The Astro setup finish message

Run these commands to enter the new project folder and start the development server:

Terminal window
cd ./astro-blog
npm run dev

Once setup is complete, it will display a message that your blog is available at http://localhost:4321/ by default.

The Astro dev server ready message

When you edit and save a file, the development server will detect the changes and reload the browser page automatically.

Uploading to GitHub#

Once you’re ready to publish your blog, you will need to push it to a GitHub repository.

Create a new repository on GitHub and follow the instructions to push your blog to the repository.

You can set the repository to public or private, it doesn’t matter.

As you chose “Yes” to initializing a git repository, all you need to do is set the remote and push:

Terminal window
# replace <URL> with your remote URL from GitHub
git remote add origin <URL>
git push -u origin HEAD

Deploying to Cloudflare#

To deploy your blog to the web, you need to connect Cloudflare to your new GitHub repository.

Sign in to the Cloudflare dashboard and head to Workers & Pages, then click the “Create application” button.

The Cloudflare setup page

Choose “Import a repository”, authenticate with GitHub, and select your new GitHub repository.

Enter a project name and click the “Create and deploy” button. Leave the rest of the options at their defaults.

The Cloudflare setup page (step 2)

That’s it! After a few moments, Cloudflare will build your blog and deploy it to the web.

Conclusion#

Now that you have linked Cloudflare to your GitHub repository, it will automatically monitor and deploy any changes that you push.

You now have a fully automated workflow for maintaining your blog.