How to scaffold a Next.js project with create-next-app
create-next-app CLI, project structure, app directory, layout.tsx, page.tsx, tsconfig, package.json scripts
Scaffolding Your Project
The fastest way to start is the official CLI. Run this in your terminal:
npx create-next-app@latest my-app --typescript --tailwind --eslint --app
cd my-app
npm run devThe --app flag opts into the App Router. The --typescript flag adds TypeScript. After scaffolding, open http://localhost:3000 โ you have a running Next.js app.
Understanding the Generated Structure
Focus on three files first:
app/
layout.tsx โ Root layout, wraps every page
page.tsx โ The / route
globals.css โ Global styleslayout.tsx is the persistent shell of your app โ navigation, fonts, and providers go here. page.tsx is the content for the / route. Any folder you create inside app/ with its own page.tsx becomes a new route.
Key npm Scripts
npm run dev # Start dev server with hot reload
npm run build # Production build
npm run start # Start production server
npm run lint # Run ESLintThe dev server watches for file changes and reloads instantly. The build command compiles, optimizes, and statically generates pages where possible. Always run build before deploying โ it catches type errors and invalid configurations that dev mode silently ignores.
