npm reports that package.json is missing.
Likely cause: The terminal is in the ZIP’s parent folder or another directory.
Check and correct: Open the extracted edushop folder that contains package.json, then run npm install there.
PROJECT 1 · LESSON 1 OF 18
Run a small website and understand which file produces the home page.
Start a new practice folder. The completed checkpoint includes all configuration and source files.
Extract the ZIP, open its project folder, and run npm install. Database lessons also need the .env.local setup described below. Checkpoints never contain credentials or node_modules.
You already know how to write a React component. The first problem is making that component available at a real URL. Next.js supplies the routing, rendering and build system around React. In this lesson, watch how a browser request reaches a page instead of treating the project as a collection of files to copy.
You will build EduShop in one folder through Projects 1–3, then return to it in Project 6. Projects 4–5 use a separate task-app folder. Keep both folders outside the EduPoly website repository.
Use Node.js 20.9 or newer and npm. These examples pin Next.js 16.3 and React 19.2. Keep Cache Components disabled for this introductory course. Basic JavaScript and React props/state are prerequisites.
React describes a user interface as a tree of components. A component returns JSX: a description of elements such as headings and paragraphs. React alone does not decide that /about should display About or provide your application’s production server. Next.js adds these application-level conventions. You still write React components, but place certain components in specially named files.
The App Router uses the app directory to define routes. app/page.tsx is the page for /. The word page is significant; Home is simply the function name we chose. Renaming Home to Welcome keeps the URL unchanged. Renaming page.tsx to welcome.tsx removes its special routing role.
The root layout supplies the HTML document around your page. Its html and body elements are required here because this is the top-level layout. children is the place where Next.js inserts the selected page. For /, children is the home-page output. Later, /about will use the same layout with a different child.
Our navigation lives outside main, while the page sits inside main. That means every page receives the same navigation without importing it separately. Do not paste a second html or body element into page.tsx: that file supplies the page content, not a second document.
package.json declares dependencies and named commands. npm install reads it and installs packages into node_modules; npm run dev executes the dev command. package-lock.json records the resolved installation and should be retained in your own project. .next contains generated output and should not be edited.
TypeScript’s .tsx extension allows JSX with type checking. tsconfig.json configures that checker and the @/* import alias. The alias lets @/components/faq refer to components/faq from the project root. next-env.d.ts supplies framework types. These setup files support the application; the visible heading still comes from app/page.tsx.
For now, npm run dev starts a development server with change detection. npm run build prepares optimized production output, and npm run start serves that output. Changing a source file while using start does not rebuild it automatically.
Read this sequence before the source. Identify the input, the component or function that handles it, and the result the learner sees.
The browser requests http://localhost:3000/.
Next.js selects app/page.tsx for the root route.
The root layout places the selected page in its children slot.
The server supplies the initial rendered document; the browser displays the heading and navigation.
npm install
npm run devThe paths below are relative to your practice project. Each block is the complete file at this checkpoint. Read its responsibility first, type or copy the code, then use the walkthrough to explain the important statements.
This is the project’s dependency and command manifest. It tells npm what to install and how to run the learner application.
{
"name": "edupoly-nextjs-lab",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"next": "16.3.0",
"react": "19.2.8",
"react-dom": "19.2.8"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19"
}
}
This configures TypeScript and module resolution; it does not define a browser route.
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"skipLibCheck": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
This declaration file makes Next.js and image-import types available to TypeScript.
/// <reference types="next" />
/// <reference types="next/image-types/global" />
This is the learner application’s framework configuration.
export default {};
This keeps generated files and local secrets out of your practice repository.
node_modules/
.next/
.env*
!.env.example
*.tsbuildinfo
This shared stylesheet makes the practice application readable without introducing a styling framework.
* {
box-sizing: border-box;
}
body {
margin: 0 auto;
max-width: 1000px;
padding: 24px;
font: 17px/1.6 system-ui;
color: #17243c;
}
nav {
display: flex;
flex-wrap: wrap;
gap: 20px;
padding: 16px 0;
border-bottom: 1px solid #ccd4e0;
}
a {
color: #174b93;
}
main {
padding: 24px 0;
}
article,
form {
border: 1px solid #ccd4e0;
padding: 18px;
margin: 16px 0;
border-radius: 10px;
}
label {
display: block;
margin: 8px 0;
}
input,
button,
select {
font: inherit;
padding: 8px;
max-width: 100%;
}
button {
cursor: pointer;
}
button:disabled {
cursor: wait;
opacity: 0.6;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 16px;
}
:focus-visible {
outline: 3px solid #d74819;
outline-offset: 3px;
}
This defines the document and shared structure surrounding the selected page.
import type { ReactNode } from "react";
import Link from "next/link";
import "./globals.css";
export const metadata = {
title: "EduShop",
description: "My Next.js learning project",
};
export default function Layout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>
<nav>
<Link href="/">Home</Link>
<Link href="/about">About</Link>
<Link href="/contact">Contact</Link>
</nav>
<main>{children}</main>
</body>
</html>
);
}
This is the first route-specific screen for the / address.
export default function Home() {
return (
<>
<h1>Welcome to EduShop</h1>
<p>Learn by building a real storefront, one feature at a time.</p>
</>
);
}
Temporarily replace {children} in the layout with the text Layout only. Predict the result, then restore it.
The navigation and Layout only remain, but the home-page heading disappears.
The page can exist and be selected correctly, yet stay invisible if the layout does not render its children. This is a composition problem rather than a missing route.
Run commands from the folder containing package.json. If port 3000 is occupied, stop the other tutorial server or use npm run dev -- --port 3001.
Likely cause: The terminal is in the ZIP’s parent folder or another directory.
Check and correct: Open the extracted edushop folder that contains package.json, then run npm install there.
Likely cause: You may be viewing another port or running the production server.
Check and correct: Use the address printed by npm run dev. If you used start, stop it and start the development server.
Add a second paragraph describing three products your store will sell.
Attempt these questions before opening the explanations. Use the source above to justify your answer.
No. app/page.tsx establishes the route. The function name can improve readability but does not define the URL.
The layout owns shared document structure. The page owns the content for one route. Keeping those responsibilities separate prevents repeated navigation and makes later routes simpler.