Introduction to Nuxt.js and Installation

Learn what Nuxt.js is, why it suits full-stack Vue applications, and how to create and run your first project.

🎯 Introduction

By the end of this article, you will understand what Nuxt.js is, the problems it solves, and why it is a common choice for server-side rendering or static generation in Vue 3 projects. You will also create and run your first Nuxt project with the official scaffolding tool and become familiar with its directory structure and common commands.


🧱 What Is Nuxt.js?

Nuxt.js is a full-stack framework built on Vue 3. It extends Vue with an integrated approach to routing, server-side rendering, static generation, auto-imports, deployment, and other application infrastructure.

Think of it as Vue with a complete set of application features:

  • File-based routing: Create a .vue file in pages/, and Nuxt automatically creates a route for it.
  • Auto-imports: Many components, composables, and utilities are imported automatically, reducing repetitive import statements.
  • Flexible rendering: Choose server-side rendering (SSR), static site generation (SSG), or client-side rendering (CSR).
  • Deployment support: Built-in commands produce output for Node.js servers, static hosting, serverless platforms, and more.
If you have built Vue 3 projects with Vite, think of Nuxt as Vite + Vue Router + SSR/SSG + project conventions, integrated to save you configuration work.

✨ Why Choose Nuxt.js?

FeatureStandard Vue 3 + Vite projectNuxt.js
RoutingConfigure vue-router manuallyGenerated from the file system
Component/utility importsManual import statementsAutomatic in many cases
SEO for initial contentRequires additional setupBuilt-in SSR / SSG
Project conventionsDefined by each developerShared directory conventions simplify teamwork
DeploymentSet up manuallyMultiple built-in deployment presets
Nuxt is well suited to medium and large projects that need routing, SEO, server features, or team collaboration. For a tiny single-page demo, Vite + Vue 3 may be a lighter choice.

🚀 Install and Create Your First Nuxt Project

Nuxt provides the official nuxi scaffolding tool to create projects. This course uses Node.js v22.0.0 and Nuxt ^3.16.0 (Nuxt 3 requires Node.js >= 18.0.0).

Run the following command to create a project:

npx nuxi@latest init my-nuxt-app
nuxi is Nuxt's official CLI. It guides you through choosing a package manager, installing dependencies, and other setup steps. You can accept the defaults throughout.

Enter the project directory and install dependencies:

cd my-nuxt-app
npm install

Start the development server:

npm run dev

Open http://localhost:3000/, the default address, to see Nuxt's welcome page.


📁 Project Structure

A basic Nuxt project has the following structure:

my-nuxt-app/
├─ .nuxt/              // Generated runtime directory for development
├─ app/
│  ├─ components/      // Auto-imported components
│  ├─ pages/           // File-based route pages
│  ├─ app.vue          // Root application component
├─ public/             // Static assets deployed directly
├─ nuxt.config.ts      // Nuxt configuration file
├─ package.json        // Project dependencies and scripts
The entry point for this Nuxt 3 project is app/app.vue, rather than the src/main.js used in a traditional Vue project. Files in pages/ are automatically registered as routes.

🛠 Common Commands

After installation, package.json includes several common scripts:

package.json
{
    "scripts": {
        "build": "nuxt build",
        "dev": "nuxt dev",
        "generate": "nuxt generate",
        "preview": "nuxt preview"
    }
}
  • npm run dev: Start the development server with hot module replacement.
  • npm run build: Create a production build (SSR mode).
  • npm run generate: Generate a static site (SSG mode) for static hosting.
  • npm run preview: Preview the production build locally.

❓ Questions and Answers

Q1: Is Nuxt.js only for Vue projects?

Yes. Nuxt is designed specifically for the Vue ecosystem and is primarily based on Vue 3.

Q2: How are Nuxt and Vite related?

Nuxt 3 uses Vite as its default build tool, so the development experience, including hot module replacement, is similar to a Vite project.

Q3: When is Nuxt unnecessary?

For a very small single page that needs neither routing nor SEO, Vite + Vue 3 is a lighter option.

Q4: How do npm run generate and npm run build differ?

build produces runtime output that supports server-side rendering. generate renders pages as static HTML at build time for static hosting.


🧪 Practice

Follow these steps to create your first Nuxt project:

  1. Create a project with npx nuxi@latest init my-nuxt-app (Node.js v18 or later is recommended).
  2. Enter the directory and run npm install to install dependencies.
  3. Run npm run dev and check that http://localhost:3000/ loads.
  4. Open app/app.vue and replace the welcome page heading with your name.
app/app.vue
<template>
    <div>
        <h1>Change the heading here</h1>
        <NuxtPage />
    </div>
</template>

🎉 You have completed your introduction to Nuxt.js! Next, we will explore directory conventions and auto-imports to see how convention over configuration simplifies development.