Skip to main content
Svelte Fundamentals
CHAPTER 02 Beginner

Installing Svelte and Environment Setup

Updated: May 18, 2026
5 min read

# CHAPTER 2

Installing Svelte and Environment Setup

1. Chapter Introduction

Setting up a Svelte development environment is remarkably fast compared to Angular or React. Because Svelte uses Vite as its build tool, the development server starts in milliseconds and updates instantly on every save. This chapter will get you from zero to a running Svelte application in under 5 minutes.

2. Learning Objectives

  • Install Node.js and verify the installation.
  • Create a Svelte project using the official Vite template.
  • Understand the project structure at a high level.
  • Start the development server and view the app in the browser.
  • Configure VS Code with essential Svelte extensions.

3. Step 1: Install Node.js

Svelte requires Node.js for its build tooling (Vite).
  1. 1. Visit nodejs.org and download the LTS version.
  1. 2. Install using default settings.
  1. 3. Verify in your terminal:
bash
12
node -v    # Should show v18.x or higher
npm -v     # Should show 9.x or higher

4. Step 2: Create a Svelte Project

The recommended way to scaffold a Svelte project is using Vite:
bash
1234567891011
# Create a new Svelte project
npm create vite@latest my-svelte-app -- --template svelte

# Navigate into the project folder
cd my-svelte-app

# Install all dependencies
npm install

# Start the development server
npm run dev

Open your browser to http://localhost:5173/ — you will see the default Svelte welcome page!

5. Alternative: SvelteKit Project

For a full-stack app with routing and SSR, use SvelteKit instead:
bash
1234
npm create svelte@latest my-sveltekit-app
cd my-sveltekit-app
npm install
npm run dev

During setup, the CLI asks:

  • App template? Choose "Skeleton project" for a clean start.
  • TypeScript? Choose based on preference (JavaScript for beginners).
  • ESLint/Prettier? Yes — great for code quality.

6. Step 3: VS Code Setup

Install these VS Code extensions for the best Svelte development experience:
  • Svelte for VS Code (by Svelte team) — syntax highlighting, autocomplete, error checking in .svelte files.
  • Prettier — consistent code formatting.
  • ESLint — code quality checks.

7. Project Folder Overview

text
123456789
my-svelte-app/
├── public/              ← Static assets (favicon, images)
├── src/
│   ├── lib/             ← Reusable components and utilities
│   ├── App.svelte        ← Root component
│   └── main.js           ← Entry point
├── index.html           ← Single HTML file (SPA shell)
├── vite.config.js       ← Vite configuration
└── package.json         ← Dependencies and scripts

8. Key package.json Scripts

json
1234567
{
  "scripts": {
    "dev": "vite",           // Start dev server (hot reload)
    "build": "vite build",   // Build for production
    "preview": "vite preview" // Preview production build locally
  }
}

9. Your First Edit

Open src/App.svelte and change the <h1> text. The browser updates instantly without refreshing — this is Vite's Hot Module Replacement (HMR)!
svelte
123456789101112131415161718
<!-- src/App.svelte -->
<script>
  let message = &#039;My First Svelte App!';
</script>

<main>
  <h1>{message}</h1>
  <p>Edit me and watch me update live! ⚡</p>
</main>

<style>
  main {
    text-align: center;
    padding: 2rem;
    font-family: sans-serif;
  }
  h1 { color: #ff3e00; }
</style>

10. Common Mistakes

  • Running npm run dev before npm install: The node_modules folder must exist. Always run npm install first after cloning or creating a project.
  • Opening index.html directly in the browser: Svelte components are compiled by Vite. You must run npm run dev and access via localhost, not by opening the file directly.

11. MCQs with Answers

Question 1

What build tool does the modern Svelte project template use?

Question 2

What command creates a new Svelte project?

Question 3

What is the default development server port for Vite?

Question 4

What command installs all project dependencies?

Question 5

What command starts the Svelte development server?

Question 6

What is the root Svelte component file called?

Question 7

What is Hot Module Replacement (HMR)?

Question 8

Where do you place static assets like images in a Svelte/Vite project?

Question 9

What is the essential VS Code extension for Svelte development?

Question 10

What does npm run build generate?

12. Interview Questions

  • Q: Why does Svelte use Vite instead of older tools like Webpack?
  • Q: Explain the difference between npm run dev and npm run build.

13. Summary

Svelte's development setup is one of the fastest and most enjoyable in the frontend ecosystem. With a single command, Vite spins up a lightning-fast server with instant HMR. The minimal project structure — just App.svelte and main.js — means you start writing meaningful code within minutes of project creation.

14. Next Chapter Recommendation

In Chapter 3: Svelte Project Structure, we demystify every file and folder generated by the template, explaining vite.config.js, the lib folder, and the crucial main.js entry point.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·