Next.js Installation
Introduction
Next.js is a popular React framework that enables features such as server-side rendering, static site generation, and API routes, making it an excellent choice for building modern web applications. In this tutorial, you'll learn how to install Next.js and set up your first project.
Before we begin, you should have:
- Basic knowledge of JavaScript and React
- Node.js (version 16.8 or later)
- npm (typically comes with Node.js) or yarn package manager
Installation Methods
There are several ways to set up a Next.js project. We'll cover the most common methods:
- Using
create-next-app
(Recommended) - Manual installation
- Adding Next.js to an existing project
Method 1: Using create-next-app
The easiest way to get started with Next.js is by using create-next-app
, which sets up everything automatically for you.
Basic Installation
npx create-next-app@latest my-next-app
# or
yarn create next-app my-next-app
# or
pnpm create next-app my-next-app
When you run this command, you'll be prompted with a series of configuration questions:
What is your project named? my-next-app
Would you like to use TypeScript? No / Yes
Would you like to use ESLint? No / Yes
Would you like to use Tailwind CSS? No / Yes
Would you like to use `src/` directory? No / Yes
Would you like to use App Router? (recommended) No / Yes
Would you like to customize the default import alias (@/*)? No / Yes
After answering these questions, the CLI will create a new directory with the name you specified and install all the necessary dependencies.
Project Structure
After installation, your project folder will look something like this:
my-next-app/
├── node_modules/
├── public/
│ ├── favicon.ico
│ ├── next.svg
│ └── vercel.svg
├── app/
│ ├── favicon.ico
│ ├── globals.css
│ ├── layout.js
│ └── page.js
├── .eslintrc.json