Next.js course Β· Module 1: Next.js Configuration
Installation and Development Environment Configuration
In this lesson15
In Quantum Metropolis, before an engineer can begin working on the city's systems, they must prepare their biometric quantum workstation. Similarly, as a Next.js developer, you must first configure your development environment. In this module, you will learn how to install and configure all the necessary tools for building applications in Next.js 16.
System Requirements
Before we begin the installation, make sure your computer meets the minimum requirements. Just as the quantum terminals in Quantum Metropolis require specific energy specifications, the Next.js environment needs appropriate software versions:
- Node.js - version 20.9 or newer (Next.js 16 no longer supports Node.js 18; the current LTS release is the best choice)
- TypeScript (optional) - version 5.1 or newer
- macOS, Windows (including WSL) or Linux
- Minimum 1GB RAM (recommended 4GB or more for larger projects)
- Code editor - recommended Visual Studio Code with React/Next.js extensions
Installing Node.js and npm
Node.js is like the quantum energy generator for your development environment - it powers all processes and tools.
Windows and macOS
- Visit the official Node.js website
- Download and install the latest LTS (Long Term Support) version
- Verify the installation by opening a terminal and typing:
node -v
npm -vYou should see the version numbers for Node.js and npm (Node Package Manager).
Linux (Ubuntu/Debian)
# Ubuntu 22.04/24.04 and Debian 12 repositories ship an old Node.js (12 or 18),
# while Next.js 16 needs 20.9 or newer. Install the current LTS from NodeSource:
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
sudo apt install nodejsManaging Node.js Versions
For more advanced users, just as Quantum Metropolis engineers use virtualization systems to test different energy configurations, you can use tools to manage Node.js versions:
- nvm (Node Version Manager) for macOS/Linux
- nvm-windows for Windows
# Installing nvm (macOS/Linux)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
# Installing a specific Node.js version
nvm install 24
nvm use 24Installing a Code Editor
In Quantum Metropolis, holographic code editors are integrated with the engineers' neural implants. Fortunately, in our world, installing a good code editor on your computer is sufficient. Visual Studio Code is currently one of the most popular editors for Next.js developers.
- Download and install Visual Studio Code
- Install useful extensions:
- ES7+ React/Redux/React-Native snippets - code templates
- ESLint - static code analysis
- Prettier - code formatting
- Tailwind CSS IntelliSense (if you plan to use Tailwind CSS)
- GitHub Copilot (optional) - AI assistant for developers
Creating a New Next.js Project
Now that you have the necessary tools installed, you can create your first Next.js 16 project. Vercel provides a convenient create-next-app tool that automatically configures the project with best practices.
npx create-next-app@latest my-quantum-appDuring installation, you will be asked to answer several configuration questions:
Would you like to use the recommended Next.js defaults? No, customize settings
Would you like to use TypeScript? Yes
Which linter would you like to use? ESLint
Would you like to use React Compiler? No
Would you like to use Tailwind CSS? Yes
Would you like your code inside a `src/` directory? Yes
Would you like to use App Router? (recommended) Yes
Would you like to customize the import alias (`@/*` by default)? No
Would you like to include AGENTS.md to guide coding agents to write up-to-date Next.js code? YesIn Next.js 16 the wizard starts by asking about the recommended defaults: the answer "Yes, use recommended defaults" selects TypeScript, ESLint, Tailwind CSS, App Router and an AGENTS.md file in one go. We choose "No, customize settings" because we also want to put our code in a src/ directory. We leave React Compiler, which memoizes components automatically, switched off for now, and AGENTS.md is a file with instructions for AI coding agents that points them to documentation matching your installed Next.js version.
We recommend answering "Yes" to most questions, especially those regarding TypeScript and App Router, which are key for modern Next.js 16 applications.
After installation is complete, navigate to the project directory and start the development server:
cd my-quantum-app
npm run devYour application should now be available at http://localhost:3000.
Alternative Installation Methods
Yarn
If you prefer to use Yarn instead of npm:
npm install -g yarn
yarn create next-app my-quantum-apppnpm
PNPM is an alternative package manager that can save disk space:
npm install -g pnpm
pnpm create next-app my-quantum-appTypeScript Configuration
TypeScript is like the security system in Quantum Metropolis - it prevents errors before they occur. Next.js has built-in TypeScript support, and the latest versions of create-next-app will configure it automatically. If you create a project manually, you can add TypeScript later:
touch tsconfig.json
npm run devNext.js will detect the tsconfig.json file, install the missing dependencies itself (typescript, @types/react, @types/node) and fill the file with the recommended configuration.
Next.js 16 Project Structure with App Router
After creating a new project, you will see the following directory structure:
my-quantum-app/
βββ node_modules/ # Installed dependencies
βββ public/ # Static files (images, fonts)
βββ src/ # Application source code
β βββ app/ # App Router directory
β β βββ layout.tsx # Main layout
β β βββ page.tsx # Home page
β β βββ globals.css # Global styles (Tailwind CSS 4 is configured here too)
βββ AGENTS.md # Guidance for AI coding agents
βββ CLAUDE.md # Points to AGENTS.md
βββ eslint.config.mjs # ESLint configuration (flat config format)
βββ next-env.d.ts # Next.js types for TypeScript
βββ next.config.ts # Next.js configuration
βββ package.json # Dependencies and scripts
βββ postcss.config.mjs # PostCSS configuration (Tailwind CSS plugin)
βββ tsconfig.json # TypeScript configurationCompared with older versions, the tailwind.config.js file is gone: Tailwind CSS 4, which create-next-app installs, is configured directly in globals.css. ESLint uses the newer eslint.config.mjs format, and the Next.js configuration is created in TypeScript right away as next.config.ts.
ESLint Configuration
ESLint is like the air quality monitoring system in Quantum Metropolis - it maintains code cleanliness and quality. create-next-app creates a basic ESLint configuration in the eslint.config.mjs file (flat config format), and the npm run lint script simply runs the eslint command. Next.js 16 removed the old next lint command and no longer lints your code during next build, so you run the linter yourself. You can extend the configuration, for example with Prettier:
npm install --save-dev eslint-config-prettier eslint-plugin-prettierThen update the eslint.config.mjs file:
// eslint.config.mjs
import { defineConfig, globalIgnores } from 'eslint/config';
import nextVitals from 'eslint-config-next/core-web-vitals';
import nextTs from 'eslint-config-next/typescript';
import prettierRecommended from 'eslint-plugin-prettier/recommended';
const eslintConfig = defineConfig([
...nextVitals,
...nextTs,
{
rules: {
'@typescript-eslint/no-unused-vars': 'warn',
},
},
prettierRecommended,
globalIgnores(['.next/**', 'out/**', 'build/**', 'next-env.d.ts']),
]);
export default eslintConfig;The eslint-plugin-prettier/recommended config turns on the prettier/prettier rule and switches off ESLint rules that would clash with Prettier's formatting, which is why it sits near the end of the list. Run the check for the whole project with npm run lint.
Prettier Configuration
Prettier is like the automatic space organization system in Quantum Metropolis - it maintains consistent code appearance. Create a .prettierrc file in the project directory:
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2
}VSCode Configuration for the Project
To fully integrate VS Code with your project, create a .vscode directory in the root of the project, and then a settings.json file inside:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
}Environment Variables Configuration
In Quantum Metropolis, every system has its special access parameters. In Next.js, we use environment variables to store sensitive information and environment-specific configurations. Create a .env.local file in the project root directory:
# Example environment variables
DATABASE_URL=your_database_url
API_KEY=your_api_key
NEXT_PUBLIC_API_URL=https://api.example.comVariables with the NEXT_PUBLIC_ prefix will also be available in the browser.
Testing the Installation
To make sure everything works correctly, modify some code in the src/app/page.tsx file and see if the changes are visible in the browser. If so, your environment is correctly configured!
Common Issues and Solutions
Port Conflicts
If port 3000 is already in use, you can run Next.js on a different port:
npm run dev -- -p 3001Node.js Issues
If you encounter version compatibility errors, make sure you are using the required version:
node -v
# If the version is too old, update Node.js or use nvmTypeScript Issues
If you encounter TypeScript errors, check if you have the appropriate types installed:
npm install --save-dev @types/react @types/nodeAdvanced Configuration
For more advanced projects, just as advanced systems in Quantum Metropolis require additional configuration, you can customize your Next.js environment:
Adding Path Aliases
Modify tsconfig.json to add path aliases:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/components/*": ["src/components/*"],
"@/lib/*": ["src/lib/*"],
"@/styles/*": ["src/styles/*"],
"@/utils/*": ["src/utils/*"]
}
}
}Test Configuration
Add Jest and React Testing Library to the project:
npm install --save-dev jest @testing-library/react @testing-library/jest-dom jest-environment-jsdomCreate a jest.config.js file:
const nextJest = require('next/jest');
const createJestConfig = nextJest({
dir: './',
});
const customJestConfig = {
setupFilesAfterSetup: ['<rootDir>/jest.setup.js'],
testEnvironment: 'jest-environment-jsdom',
};
module.exports = createJestConfig(customJestConfig);Then create a jest.setup.js file:
import '@testing-library/jest-dom';Summary
Congratulations! Just like an engineer in Quantum Metropolis who completed their workstation configuration, you now have a fully configured development environment for Next.js 16. Your holographic terminals (code editor) are ready, the quantum reactor (Node.js) is running, and the security systems (TypeScript, ESLint) are active.
In the next lesson, we will learn more about project initialization and available starters that will help you start working on specific types of applications more quickly.
Code for this lesson: index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Virtual DOM - Metropolis Quantum</title>
<style>
body {
font-family: 'Courier New', monospace;
background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 100%);
color: #64ffda;
padding: 20px;
margin: 0;
}
.container {
max-width: 800px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.1);
padding: 20px;
border-radius: 10px;
border: 1px solid #64ffda;
}
h1 {
color: #64ffda;
text-align: center;
}
.comparison {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-top: 20px;
}
.method {
background: rgba(0, 0, 0, 0.5);
padding: 15px;
border-radius: 8px;
border: 2px solid #448aff;
}
.method h3 {
color: #448aff;
margin-top: 0;
}
.demo-box {
background: rgba(100, 255, 218, 0.1);
padding: 10px;
border-radius: 5px;
margin: 10px 0;
border: 1px solid #64ffda;
}
button {
background: linear-gradient(45deg, #7c4dff, #e91e63);
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-weight: bold;
margin: 5px;
}
button:hover {
transform: scale(1.05);
box-shadow: 0 5px 15px rgba(124, 77, 255, 0.4);
}
</style>
</head>
<body>
<div class="container">
<h1>Virtual DOM vs Real DOM</h1>
<div class="comparison">
<div class="method">
<h3>Traditional DOM Manipulation</h3>
<div id="traditional-demo" class="demo-box">
Counter: <span id="trad-count">0</span>
</div>
<button onclick="traditionalUpdate()">Update (Slow)</button>
<p>Every change β Full page re-render</p>
</div>
<div class="method">
<h3>Virtual DOM (React Way)</h3>
<div id="virtual-demo" class="demo-box">
Counter: <span id="virt-count">0</span>
</div>
<button onclick="virtualUpdate()">Update (Fast)</button>
<p>Change β Diff β Only necessary updates</p>
</div>
</div>
<div style="margin-top: 30px; background: rgba(124, 77, 255, 0.2); padding: 15px; border-radius: 8px;">
<h3>How does Virtual DOM work?</h3>
<ol style="line-height: 1.8;">
<li>React creates a virtual representation of the DOM in memory</li>
<li>On state change - creates a new Virtual DOM</li>
<li>Compares (diffing) old with new Virtual DOM</li>
<li>Updates only changed parts in the real DOM</li>
<li>Result: Faster and more efficient applications!</li>
</ol>
</div>
</div>
<script>
let tradCount = 0;
let virtCount = 0;
// Traditional DOM - slower method
function traditionalUpdate() {
tradCount++;
console.log("Traditional update - entire element is re-rendered");
document.getElementById('trad-count').textContent = tradCount;
// Simulation of slower operation
document.getElementById('traditional-demo').style.background = 'rgba(244, 67, 54, 0.3)';
setTimeout(() => {
document.getElementById('traditional-demo').style.background = 'rgba(100, 255, 218, 0.1)';
}, 200);
}
// Virtual DOM simulation - faster method
function virtualUpdate() {
virtCount++;
console.log("Virtual DOM update - only necessary changes");
document.getElementById('virt-count').textContent = virtCount;
// Simulation of faster operation
document.getElementById('virtual-demo').style.background = 'rgba(76, 175, 80, 0.3)';
setTimeout(() => {
document.getElementById('virtual-demo').style.background = 'rgba(100, 255, 218, 0.1)';
}, 100);
}
console.log("Virtual DOM Demo - Metropolis Quantum");
console.log("Click the buttons to see the difference in action!");
</script>
</body>
</html>Docs entries used in this lesson
Spotted a mistake in this lesson?
Check yourself
Answer the questions from this lesson. Pick an answer to see right away whether it is correct.
1. Next.js was released in:
2. JSX is:
3. Virtual DOM in React is used for:
Hands-on tasks in the game
- Vertical ordering
Arrange the syntax for a default export of a page component in Next.js