🎓 A1Learner
🔍
0 of 50 lessons completed

Next.js The Production Build

npm run build makes the fast version of the app. npm start serves it.

The build passes

Two lines prove the build. The code compiled, and TypeScript passed.

npm run build

The server starts

One command starts the prod server. The last line says it is ready. The network line shows this machine address, and yours will differ.

npm start

Example

for r in / /books/dune "/search?q=dune" /gallery /cached /env; do printf "%s " "$r"; curl -s -o /dev/null -w "%{http_code}\n" "http://localhost:3110$r"; done

Key points

  • The build compiled in 38.5 seconds. TypeScript passed too.
  • The route table is the same as in the earlier lesson. The marks did not change.
  • npm start was ready in 1435ms. The app served on port 3110.
  • All six capstone routes answered 200. The home, book, search, gallery, cached, and env pages all answer.
  • Dev is for building. Prod is for serving. The two servers are not the same.

In this example, one loop asks for all six routes. Each line prints the route and its answer. All six answer 200. The home page, the book page, the search page, the gallery, the cached page, and the env page all serve from the prod server. Six routes, six 200s, and the finished app is live on this machine.

Note

Build before you ship. A green build means the app is ready to serve.

Try it Yourself

Edit the code, then press Run.

Running is simulated · TypeScript Playground

Exercise

What does npm start do?