Next.js is a React framework that allows developers to build full-stack web applications. It provides features like:
- Server-Side Rendering (SSR)
- Static Site Generation (SSG)
- API routes
- Built-in routing
- Performance optimization
- SEO improvements
The fastest way to create a new Next.js application is by using the official CLI.
Run the following command in your terminal:
npx create-next-app@latest my-app --yes
The --yes flag skips all interactive prompts and uses the recommended default configuration.
Default setup includes:
@/*cd my-appnpm run dev
Once the server is running, open your browser and visit:
http://localhost:3000
You should now see your Next.js application running locally 🎉
Next.js comes with built-in TypeScript support, so no manual setup is required.
Rename any JavaScript file to .ts or .tsx
Run the development server with npm run dev
Next.js will automatically:
tsconfig.jsonThis makes it easy to start using TypeScript without additional configuration.
Next.js supports linting using ESLint or Biome. Choose one based on your preference.
Add the following scripts to your package.json:
{"scripts": {"lint": "eslint","lint:fix": "eslint --fix"}}
Run linting with:
npm run lint
Next.js supports absolute imports using the baseUrl and paths options in tsconfig.json or jsconfig.json.
They make imports cleaner and easier to maintain.
// Beforeimport { Button } from '../../../components/button'// Afterimport { Button } from '@/components/button'
baseUrl{"compilerOptions": {"baseUrl": "src/"}}
{"compilerOptions": {"baseUrl": "src/","paths": {"@/styles/*": ["styles/*"],"@/components/*": ["components/*"]}}}
Each alias is resolved relative to the baseUrl.