Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Your First Next.js App  ›  Lesson

create-next-app

create-next-app 12 mincreate-next-app scaffolds a working Next.js project with the app folder, config and scripts, so you can start the dev server with one command.

create-next-app

Setting up a React project by hand means choosing a bundler, a TypeScript setup, a linter, a dev server and a folder layout, then wiring them together. For Trailhead we skip all of that. One command produces a project that already runs.

The rule

One command scaffolds it; dev to build, build then start to ship.

Run the official starter with a project name:

npx create-next-app@latest trailhead

It asks a few questions, such as whether to use TypeScript, a linter, Tailwind CSS, a src/ folder and the App Router. Accepting the recommended answers is a sensible start. Then you get a folder like this:

trailhead/
  app/
    layout.tsx      # the shell around every page
    page.tsx        # the home page, at /
    globals.css     # styles for the whole site
  public/           # files served as-is, e.g. /logo.png
  next.config.ts    # Next.js settings
  package.json      # dependencies and scripts
  tsconfig.json     # TypeScript settings

The three scripts in package.json are the ones you use every day:

Script What it does When
npm run dev Starts the development server with fast refresh While writing code
npm run build Creates an optimised production build Before deploying
npm run start Serves the finished build In production

After npm run dev, open http://localhost:3000. Edit app/page.tsx, save, and the browser updates without losing its place.

Files in public are served from the site root: public/trail-map.png is at /trail-map.png. Do not put secrets there. Everything in it is public.

The shortcut

Think of the scripts as a pipeline: write with dev, freeze with build, serve with start. start can only serve what build produced, so after changing code you build again.

From nothing to Trailhead's home pageStep 1 of 4
  1. Scaffold

    npx create-next-app@latest trailhead, accept the recommended options, then cd trailhead.

The trap is judging speed from npm run dev. The dev server compiles pages on demand and adds debugging help, so it is slower than production. Measure with build and start.

Drills

Answer fast — trust the rule.

quick drill

Which command creates a new Next.js project called trailhead?

quick drill

You add public/icons/boot.svg. At what URL is it served?

quick drill

You changed code and want to check the production version locally. What do you run?

quick drill

Which file is the home page of a new project?

Remember

  • One command scaffolds the project; app/page.tsx is the home page and public maps to the root.
  • Shortcut: write with dev, freeze with build, serve with start.
  • Trap: judging performance from the dev server, or putting secrets in public.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainTour the new project

You have just run npx create-next-app@latest trailhead. Explain what the app folder, the public folder and the dev, build and start scripts are each for, and what you do to see the site in a browser.