Getting Started

Welcome to the Next.js documentation!

If you’re new to Next.js we recommend that you start with the learn course.

The interactive course with quizzes will guide you through everything you need to know to use Next.js.

If you have questions about anything related to Next.js, you’re always welcome to ask our community on GitHub Discussions.

System Requirements

  • Node.js 10.13 or later
  • MacOS, Windows (including WSL), and Linux are supported

Setup

We recommend creating a new Next.js app using create-next-app, which sets up everything automatically for you. To create a project, run:

  1. npx create-next-app
  2. # or
  3. yarn create next-app

After the installation is complete, follow the instructions to start the development server. Try editing pages/index.js and see the result on your browser.

For more information on how to use create-next-app, you can review the create-next-app documentation

Manual Setup

Install next, react and react-dom in your project:

  1. npm install next react react-dom
  2. # or
  3. yarn add next react react-dom

Open package.json and add the following scripts:

  1. "scripts": {
  2. "dev": "next dev",
  3. "build": "next build",
  4. "start": "next start"
  5. }

These scripts refer to the different stages of developing an application:

  • dev - Runs next dev which starts Next.js in development mode
  • build - Runs next build which builds the application for production usage
  • start - Runs next start which starts a Next.js production server

Next.js is built around the concept of pages. A page is a React Component exported from a .js, .jsx, .ts, or .tsx file in the pages directory.

Pages are associated with a route based on their file name. For example pages/about.js is mapped to /about. You can even add dynamic route parameters with the filename.

Create a pages directory inside your project.

Populate ./pages/index.js with the following contents:

  1. function HomePage() {
  2. return <div>Welcome to Next.js!</div>
  3. }
  4. export default HomePage

To start developing your application run npm run dev or yarn dev. This starts the development server on http://localhost:3000.

Visit http://localhost:3000 to view your application.

So far, we get:

In addition, any Next.js application is ready for production from the start, read more in our Deployment documentation.

Related

For more information on what to do next, we recommend the following sections:

Pages

Learn more about what pages are in Next.js.

CSS Support

Use the built-in CSS support to add custom styles to your app.

CLI

Learn more about the Next.js CLI.