Next.js CLI

The Next.js CLI allows you to start, build, and export your application.

To get a list of the available CLI commands, run the following command inside your project directory:

  1. npx next -h

(npx comes with npm 5.2+ and higher)

The output should look like this:

  1. Usage
  2. $ next <command>
  3. Available commands
  4. build, start, export, dev, telemetry
  5. Options
  6. --version, -v Version number
  7. --help, -h Displays this message
  8. For more information run a command with the --help flag
  9. $ next build --help

You can pass any node arguments to next commands:

  1. NODE_OPTIONS='--throw-deprecation' next
  2. NODE_OPTIONS='-r esm' next
  3. NODE_OPTIONS='--inspect' next

Build

next build creates an optimized production build of your application. The output displays information about each route.

  • Size – The number of assets downloaded when navigating to the page client-side. The size for each route only includes its dependencies.
  • First Load JS – The number of assets downloaded when visiting the page from the server. The amount of JS shared by all is shown as a separate metric.

The first load is colored green, yellow, or red. Aim for green for performant applications.

You can enable production profiling for React with the --profile flag in next build. This requires Next.js 9.5:

  1. next build --profile

After that, you can use the profiler in the same way as you would in development.

You can enable more verbose build output with the --debug flag in next build. This requires Next.js 9.5.3:

  1. next build --debug

With this flag enabled additional build output like rewrites, redirects, and headers will be shown.

Development

next dev starts the application in development mode with hot-code reloading, error reporting, and more:

The application will start at http://localhost:3000 by default. The default port can be changed with -p, like so:

  1. npx next dev -p 4000

Production

next start starts the application in production mode. The application should be compiled with next build first.

The application will start at http://localhost:3000 by default. The default port can be changed with -p, like so:

  1. npx next start -p 4000

Telemetry

Next.js collects completely anonymous telemetry data about general usage. Participation in this anonymous program is optional, and you may opt-out if you’d not like to share any information.

To learn more about Telemetry, please read this document.