How To Get Started With Astro

Written by Sebastian on August 19, 2022 · 4 min read

tutorial

Astro is a relatively new web frameworks which helps you to build fast and clean websites with ease. Astro is able to work together with all all major JavaScript front-end frameworks like React, Vue, or Svelte.

Astro describes itself as “an all-in-one web framework for building fast, content-focused websites”. The framework introduces some key features which makes it stand out from the long list of web frameworks available today. Astro works like a static side generator and tries to generate a static version of your website on server side and reduce the amount of code which is send to the client to the smallest amount possible. This helps to make the website very fast.

Here are some of the most important features of Astro:

Step 1: Setup A New Astro Project

In order to create a new Astro project you can use the Node.js Package Manager command line tool NPM in the following way:

$ npm create astro@latest

This command starts up the command line wizard which guides you through the process of setting up a new Astro project from scratch. Here you need to provide answers to a few questions:

First you need to confirm to install the create-astro package

First you need to confirm that the create-astro package is being installed. You can simply hit return to confirm this question and proceed with the setup procedure in the following.

In the next step the wizard is asking where to store the new project. The default proposal which is made here is: ./my-astro-site.

The Astro setup process is asking for the location of the new project

If you just hit return a new project folder my-astro-site is created in the current directory.

The next question which needs to be answered is whether you’d like to start with a template or without:

You can choose to setup an Astro project with template or without

To keep things simple we’ll just use the first option (Just the basics) which is setting up a very small default Astro project without any special template.

Next you need to decide if you want to get NPM dependencies installed. The default option is Yes and you should just hit return to confirm this default option:

NPM dependencies can be installed automatically

In the next step you have the option to automatically initiate a new Git repository for the new project:

You can choose to initialize a Git repository for the new Astro project

Finally you need to decide if you want to have TypeScript enables for the project. The project is then created and the setup procedure is fully completed.

Completing the Astro project setup wizard

Step 2: Start Astro

In order to start the Astro web server and access the web application in the browser you first need to change into the newly created project folder by typing in the following command:

$ cd my-astro-site

Now you’re ready to execute the start script by using NPM:

$ npm run start

You should then be able to see the following output on the command line:

Starting the Astro web server

Here you’re being told that the server is running on http://localhost:3000 Open the browser and type in this URL to access the output of the default Astro project setup.

The result should look like what you can see in the following screenshot:

Output of the default Astro project in the browser

Step 3: Get Familiar With The Project Structure

Now you’ve managed to setup you first Astro project. Let’s dive a little bit into Astro’s project structure. In every Astro project you should at least find the following folder structure:

And the following files in the root project folder: