Skip to content

Run It with Real Next.js

The Course
•
20 min study

This lesson runs on your own computer. You need Node.js 20.9 or later (node --version) and a code editor.

1. Download and run

Press Download project under the Study Notes lab in the first lesson, unzip it, and open a terminal in the study-notes folder:

Shell
npm install
Shell
npm run dev

Open http://localhost:3000. It's the same app, now served by real Next.js 16.4.3, the version the labs were checked against.

Three things to notice:

  • Server logs originate on the server. The lines marked [server] in the labs print in the terminal running npm run dev. Development tooling may forward server logs to browser devtools too; that doesn't make them client code.
  • Edits appear as you save. Change a heading and save: the page updates without a reload.
  • A new AGENTS.md file. next dev writes one into the project the first time it runs, with notes for AI coding tools. You can delete it, or turn it off in next.config.

Open http://localhost:3000/api/notes in the browser: the JSON from Day 6.

2. Build for production

next dev is for working. A real site runs a production build, which is optimised and faster:

Shell
npm run build
Shell
npm start

npm run build ends with a table of routes:

Text
┌ ƒ /
├ ƒ /_not-found
├ ƒ /api/notes
├ ƒ /new
├ ƒ /notes/[id]
└ ƒ /settings
ƒ  (Dynamic)  server-rendered on demand

ƒ means dynamic: built fresh for every request. Every route here is dynamic in this example. The root layout's theme cookie makes the page routes request-dependent. Route handlers don't render through the layout; /api/notes stays dynamic because this handler reads its request URL and uses the default uncached GET behaviour.

Static and dynamic

When a page doesn't depend on the request, Next.js builds it once, at build time, and serves that copy to everyone. That's marked ○ (static), and it's as fast as serving a file.

Exercise

Find the static pages

In app/layout.jsx, replace the cookie line with const theme = "light"; and remove the cookies import. Run npm run build again. Which routes become ○, and why do the others stay ƒ?

Hint 1: the idea

Static rendering depends on request-specific work in that route and its layouts. API routes do not inherit the page layout.

Hint 2: a first step

For each page, ask: does it read anything from the request, such as searchParams, params for an id that isn't known in advance, or cookies?

Show one solution

/new and /_not-found become ○: nothing about them depends on the request. / reads searchParams, /notes/[id] depends on which id is asked for, /settings still reads the cookie itself, and route handlers like /api/notes read the request, so those stay ƒ. Undo the change afterwards.

What the labs did differently

The labs follow Next.js closely, but they run in your browser with no real server. You've met most of the differences already:

In the labsIn real Next.js
Client components render only in the browser, so reading window during render seems fineClient components render on the server first, so window during render fails (Day 2)
Math.random(), Date.now() or toLocaleString() during a client component's render shows no errorThe server's and the browser's first renders must match; if they don't, next dev reports Hydration failed… (Day 2)
error.jsx receives retry, as Next.js 16.4 doesProjects on older versions get unstable_retry (16.2) or only reset (15); the downloads pin 16.4.3 (Day 4)
A plain <a> keeps the page's stateA plain <a> reloads the whole site; Link doesn't (Day 1)
Every Run restarts the server, emptying memoryMemory lasts until the server restarts; editing a file in next dev can reset it too
Error messages from the server show in fullA production build hides them from the browser (Day 4)
Everything is dynamic, like next devnext build makes pages static when it can

Deploying

To put the app on the internet, a host has to run npm run build and npm start for you. Vercel, the company behind Next.js, does this from a GitHub repository with no setup, and many other hosts support Next.js too. One changes first: replace the in-memory list with persistent storage, and decide who may create or delete notes. Memory is lost on restart and isn't shared between server instances. A multi-user deployment also needs server-side permission checks; a working form isn't an access policy.

Was this article helpful?

Your response is saved on this device.