Next.js on localhost:3000
Next.js development server runs on port 3000 by default with fast refresh, hot module replacement, and automatic routing. This is the standard port for React-based Next.js applications.
→ Open localhost:3000Create New Next.js Application
Next.js Commands
Next.js Project Structure
App Router (Next.js 13+)
Pages Router (Legacy)
File-Based Routing
| File | Route | Description |
|---|---|---|
| app/page.js | / | Home page |
| app/about/page.js | /about | About page |
| app/blog/page.js | /blog | Blog index |
| app/blog/[slug]/page.js | /blog/:slug | Dynamic route |
| app/api/users/route.js | /api/users | API endpoint |
Create Pages
Simple Page (App Router)
Dynamic Route
API Routes
Create API Endpoint
Access API from Client
Data Fetching
Server Components (Default)
Client Components
Configure Next.js
next.config.js
Environment Variables
Fix "Next.js localhost Not Working"
Issue: Port 3000 already in use
Issue: Fast refresh not working
- Check file is inside src/ or app/ directory
- Restart dev server
- Clear .next folder:
rm -rf .next - Check console for errors
Issue: Module not found
Issue: Page not found (404)
- Verify file is named page.js (not index.js in App Router)
- Check file is in correct directory
- Restart dev server
Change Next.js Port
Next.js Features
- Fast Refresh - Instant feedback on edits
- File-based Routing - Automatic route creation
- API Routes - Backend API endpoints
- Server Components - React Server Components support
- Image Optimization - Automatic image optimization
- TypeScript - Built-in TypeScript support
- CSS Support - CSS Modules, Sass, Tailwind
- SEO - Built-in metadata and head management
Production Build
Frequently Asked Questions
What port does Next.js use?
Next.js uses port 3000 by default for development. You can change it using the PORT environment variable or -p flag.
Do I need a backend for Next.js?
No, Next.js includes API Routes that let you build backend endpoints within your Next.js application. However, you can connect to external APIs if needed.
What's the difference between App Router and Pages Router?
App Router (Next.js 13+) uses the app/ directory and supports React Server Components. Pages Router uses pages/ directory. App Router is recommended for new projects.
Can I use Next.js without Node.js?
No, Next.js requires Node.js to run. However, you can deploy as a static site (next export) which doesn't need Node.js at runtime.
How do I deploy Next.js from localhost?
Use Vercel (recommended), Netlify, or any hosting that supports Node.js. Run npm run build, then deploy the .next folder and node_modules.
Related Resources
- localhost:3000 - Port 3000 guide
- localhost:3001 - Alternative port
- localhost/api - API development
- localhost:5173 - Vite (React alternative)