Set up a Next.js project and start building pages and API routes quickly.
npx create-next-app@latest my-app
cd my-app
npm run devnpx create-next-app@latest my-app --ts --app --tailwindnpm install && npm run devmy-app/
app/
page.tsx # / route
about/
page.tsx # /about route
blog/
[slug]/
page.tsx # /blog/:slug route
public/ # Static files
package.jsonpublic/
logo.png # /logo.png
favicon.ico # /favicon.ico// app/layout.tsx
export default function RootLayout({ children }) {
return <html lang="en"><body>{children}</body></html>;
}// app/api/health/route.ts
export async function GET() {
return Response.json({ status: "ok" });
}// app/page.tsx
export default function Home() {
return (
<main>
<h1>Welcome to Next.js</h1>
<p>Get started by editing this page</p>
</main>
);
}// app/about/page.tsx
export default function About() {
return <h1>About Us</h1>;
}export default async function Blog() {
const posts = await getPosts();
return <ul>{posts.map(p => <li key={p.id}>{p.title}</li>)}</ul>;
}export const metadata = {
title: "Home",
description: "Welcome to my Next.js site"
};"use client";
import { useState } from "react";
export default function Counter() {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(count + 1)}>Count: {count}</button>;
}npm run build
npm start
# Route Size First Load JS
# / 3 kB 87 kB ← aim for < 130 kBnpm run build 2>&1 | grep "First Load JS"
# Flag any route above 130 kB for optimisationnpm install -g vercel
vercel # auto-detected, deployed immediatelyvercel env add DATABASE_URL production
vercel env add NEXT_PUBLIC_API_URL production// next.config.js
module.exports = { output: "standalone" };npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -pimport Link from "next/link";
export default function Nav() {
return <nav><Link href="/about">About</Link></nav>;
}npm install prisma @prisma/client
npx prisma init
npx prisma db push # sync schema to databasenpm install next-auth
# or
npm install @clerk/nextjsimport Image from "next/image";
<Image src="/hero.jpg" alt="Hero" width={1200} height={600} priority />Run npx create-next-app@latest my-app and follow the interactive prompts to configure TypeScript, ESLint, and Tailwind CSS. The scaffolded project includes the app router, proper folder structure, and all dependencies pre-installed.
The app directory uses the newer App Router with React Server Components by default, while pages uses the legacy Pages Router. New projects should use app — it supports co-located layouts, loading UI, and server actions that the Pages Router lacks.
Create nested folders inside app, and any folder containing a page.tsx file becomes a URL segment. For example, app/dashboard/settings/page.tsx maps to /dashboard/settings, and you can add a shared layout.tsx at any level to wrap child routes.
Run npm run build to generate an optimized production build in the .next folder, then npm start to serve it. For Vercel deployments, pushing to your connected repo triggers both steps automatically with zero configuration.
The App Router only treats a file named exactly page.tsx (or page.js) as a route — other filenames like index.tsx or home.tsx inside a folder are ignored as routes. Make sure the file is named page.tsx and lives inside the app directory, then restart the dev server.