Next.js is a popular React framework known for its simplicity and
efficiency in developing modern web applications. One of the quickest
ways to start a new Next.js project is by using
create-next-app
, an official Next.js tool that simplifies
the setup of a new project. This article will guide you through the
steps to create a Next.js project using
create-next-app
.
Ensure that Node.js is installed on your system, as
create-next-app
requires Node.js.
To start a new Next.js project, open your terminal and execute the following command:
npx create-next-app my-next-project
This command creates a new directory named
my-next-project
and installs all necessary
dependencies.
After installation, navigate to the project directory:
cd my-next-project
Start the development server with:
npm run dev
or, if you are using yarn:
yarn dev
Once the server is running, you can visit your new Next.js
application at http://localhost:3000
in your web
browser.
create-next-app
creates a standard project structure for
you:
pages/
: Contains your page components. Each file in
this directory becomes a route in your application.public/
: For static files like images.styles/
: Place your CSS files here.From here, you can further develop and customize your project. Add new pages, edit the existing ones, and add your business logic.
Create a Next.js project using create-next-app
and
utilize the new feature where it asks if a “src” directory should be
used. This feature organizes your project files within a
src
directory, promoting a cleaner project structure.
create-next-app
command to create a new Next.js
project.src
directory.