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.
Visit
nodejs.organd download the LTS version.
- 2. Install using default settings.
- 3. Verify in your terminal:
bash
4. Step 2: Create a Svelte Project
The recommended way to scaffold a Svelte project is using Vite:
bash
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
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
.sveltefiles.
- Prettier — consistent code formatting.
- ESLint — code quality checks.
7. Project Folder Overview
text
8. Key package.json Scripts
json
9. Your First Edit
Opensrc/App.svelte and change the <h1> text. The browser updates instantly without refreshing — this is Vite's Hot Module Replacement (HMR)!
svelte
10. Common Mistakes
-
Running
npm run devbeforenpm install: Thenode_modulesfolder must exist. Always runnpm installfirst after cloning or creating a project.
-
Opening
index.htmldirectly in the browser: Svelte components are compiled by Vite. You must runnpm run devand access vialocalhost, 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 devandnpm 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 — justApp.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, explainingvite.config.js, the lib folder, and the crucial main.js entry point.