The fastest way to start a Next.js project is the official scaffolding tool, create-next-app. In this lesson you will generate a fresh project, run the development server, and tour every file and folder so nothing in the project feels mysterious. Understanding the structure now will pay off in every later lesson.
Make sure you have Node.js 18.18 or newer, then run:
npx create-next-app@latest my-next-appThe installer asks a series of questions. Recommended answers for this course:
When it finishes, start the dev server:
cd my-next-app
npm run devOpen http://localhost:3000 and you will see the starter page. The dev server supports Fast Refresh: edit a file, save, and the browser updates instantly without losing state.
A fresh project looks like this:
my-next-app/
├── app/
│ ├── favicon.ico
│ ├── globals.css
│ ├── layout.js
│ └── page.js
├── public/
├── next.config.mjs
├── package.json
├── jsconfig.json (or tsconfig.json)
└── eslint.config.mjsThis is the heart of the App Router. Every folder inside app can become a URL segment, and special file names have special jobs. page.js defines the UI for a route, and layout.js defines UI that wraps pages. The root layout.js is required: it renders the html and body tags for the entire application.
// app/layout.js
import './globals.css';
export const metadata = {
title: 'My Next App',
description: 'Learning Next.js on CodeYourCraft',
};
export default function RootLayout({ children }) {
return (
<html lang='en'>
<body>{children}</body>
</html>
);
}The children prop is where each page gets rendered. globals.css holds styles that apply everywhere and is imported once, here in the root layout.
Static assets like images, fonts, and robots.txt live in public. A file at public/logo.png is served at /logo.png. Nothing in public is processed by the bundler, so use it for files that should be served exactly as-is.
npm run dev # development server with Fast Refresh
npm run build # optimized production build
npm run start # serve the production build locallyRun npm run build now, just to see the output. Next.js prints a route table showing which routes are static and how large each bundle is. Reading this table is a habit worth forming early.
Open app/page.js, delete the starter content, and replace it with a simple component of your own. Save, and watch the browser update. Congratulations - you are officially developing with Next.js.
Next up: Lesson 3 explores file-based routing in depth - how folders, pages, and nested routes map to URLs.