NextJS Key concepts

1/1/1970

NextJS Key concepts

Installation

Automatic Installation :

npx create-next-app@latest

Manual Installation:

npm install next@latest react@latest react-dom@latest

Open your package.json file and add the following scripts:

// package.json
{
  "scripts": {
    "dev": "next dev", // to start Nextjs in development mode.
    "build": "next build", // to build the app. for production usage.
    "start": "next start", // to start a Nextjs production server.
    "lint": "next lint" //  to set up Nextjs built-in ESLint configuration.
  }
}
  1. Create a pages directory at the root of your project. Then, add an index.tsx file inside your pages folder. This will be your home page (/):
  2. Next, add an _app.tsx file inside pages/ to define the global layout. Learn more about the custom App file.
  3. Finally, add a _document.tsx file inside pages/ to control the initial response from the server. Learn more about the custom Document file.

1. File-Based Routing


2. Pre-rendering and Data Fetching


3. API Routes


4. Built-in CSS and Styling Options


5. Middleware and Edge Functions (Optional)


6. Static File Serving


7. Head Management


8. Image Optimization


9. Custom _app.js and _document.js


10. Deployment


Additional Tips:

By focusing on these core features, you’ll quickly become proficient in Next.js. Start with small projects, like converting an existing React app to Next.js!