Create Your First Next.js App and Understand the Folders

Next.js Course: Beginner to Advanced with Examples · Next.js Introduction · 5 min read · Updated

Create, run, build

  1. create-next-app makes a ready project with the app folder and settings.
  2. npm run dev starts the development server. Edits show up at once.
  3. npm run build prepares the site for real visitors and prints the route list.
  4. npm run start serves the built site, the way a real server would.

Time to build something. In this lesson you will install what you need, create a project, look at every file and folder, run it on your computer and make a production build. Go slowly and type the commands yourself. Do not worry if you see more files than you expected. We explain them one by one.

Step 1: Install Node.js

Next.js runs on Node.js, which lets JavaScript run outside the browser. Next.js 16 needs Node.js 20.9 or newer. Check your version by opening a terminal and typing the first command below. If you see a number lower than 20.9 or an error, install the current LTS version from nodejs.org. LTS means long-term support, which is the safe choice.

node -v
npm -v

npm comes with Node.js. It installs packages, which are pieces of code written by other people. You can also use pnpm or yarn if you already prefer them.

Step 2: Create the project

Run the command below in a folder where you keep your projects. The name my-app is the name of the new folder. You can choose another name using lowercase letters and dashes.

npx create-next-app@latest my-app

The tool asks a few questions. If you are not sure, take the recommended answers. They are TypeScript yes, ESLint yes, Tailwind CSS yes and App Router yes. TypeScript adds types that catch mistakes early, ESLint checks your code style and Tailwind is a way to style with small classes. You can also give your answers in the command itself. The lessons in this course use this version, which turns off the optional src folder.

npx create-next-app@latest my-app --ts --tailwind --eslint --app --no-src-dir --import-alias "@/*" --use-npm

Step 3: Look at the folders

npx create-next-app@latest my-app --ts --tailwind --eslint --app --no-src-dir --import-alias "@/*" --use-npm
...
Success! Created my-app

my-app/
  app/            layout.tsx, page.tsx, globals.css, favicon.ico
  public/         static files such as images
  AGENTS.md  README.md  eslint.config.mjs  next-env.d.ts
  next.config.ts  package.json  tsconfig.json
  • app: the heart of your site. Every folder inside becomes part of a URL. layout.tsx wraps all pages and page.tsx is the home page. globals.css holds styles for the whole site.
  • public: files served exactly as they are, such as images and icons. A file public/logo.png is available at /logo.png.
  • next.config.ts: settings for Next.js. You will rarely touch it at the start.
  • package.json: lists your packages and the commands you can run.
  • tsconfig.json: settings for TypeScript. The import alias @/* lets you write imports from the project root, such as @/components/Button.
  • eslint.config.mjs: rules for ESLint.
  • node_modules: the downloaded packages. Never edit it and never upload it to Git.
  • AGENTS.md: a note for AI coding tools. Some versions of the generator add it. You can read it or ignore it.

Step 4: Run the development server

cd my-app
npm run dev

Open http://localhost:3000 in your browser. You will see the starter page. Now open app/page.tsx, change the text and save. The page updates without a refresh. This is called Fast Refresh, and it is one reason development feels quick. The dev server shows detailed errors and builds pages on demand, so it is slower and bigger than a real release.

Step 5: Make a production build

A production build prepares the site the way real visitors will get it. Run the two commands below. The first one builds and prints a list of your routes. The second one starts the real server on port 3000.

npm run build
npm run start

Always run a build before you deploy, because some mistakes show up only there. For example, a page that reads request data outside the proper place stops the build with a clear message. Read the message. It tells you how to fix it.

The four commands you will use all the time

  • npm run dev: development server with Fast Refresh.
  • npm run build: production build and route list.
  • npm run start: run the production build.
  • npm run lint: check the code with ESLint, if your project has this script.

Your first edit

Replace the content of app/page.tsx with a simple page of your own. The example below is the home page we use in the following lessons. It has a heading, a navigation bar and a small search box. We will explain the pieces later in the course.

import { Suspense } from "react";
import NavLinks from "@/components/NavLinks";
import SearchBox from "@/components/SearchBox";

export default function Home() {
  return (
    <main className="p-6">
      <NavLinks />
      <h1>Welcome</h1>
      <Suspense fallback={<p>Loading search...</p>}>
        <SearchBox />
      </Suspense>
    </main>
  );
}

Your task

  1. Check your Node.js version and install a newer one if it is lower than 20.9.
  2. Create the project with create-next-app and start it with npm run dev.
  3. Change the heading in app/page.tsx and watch the page update.
  4. Stop the server, run npm run build and write down the route list that you see.

How to check it worked

  • http://localhost:3000 shows your page.
  • npm run build finishes without an error and prints a route list.
  • You can say what the app, public and node_modules folders are for.

Frequently asked questions

Which Node.js version do I need?

Next.js 16 needs Node.js 20.9 or newer. Use the current LTS version from nodejs.org.

Should I use the src folder?

It is optional. It keeps your code in src and leaves config files outside. This course does not use it, so the paths in the lessons match your project.

Why is npm run dev slower than the real site?

The dev server builds pages when you ask and adds helpful error tools. A production build is prepared ahead of time and optimised, so it is faster for visitors.