Next.js CLI Available Commands

Commands

By Chandrashekhar Fakirpure

Updated on Jan 26, 2024

In this tutorial, we will explore Next.js CLI available commands. We have discussed about list of the useful available CLI commands. Execute following commands inside your project directory.

Get help 

npx next -h 

The output should similar like:

Usage
  $ next <command>

Available commands
  build, start, export, dev, lint, telemetry, info, experimental-compile, experimental-generate

Options
  --version, -v   Version number
  --help, -h      Displays this message

For more information run a command with the --help flag
$ next build --help

Production build To create optimized production build application, execute following command: 

npx next build

It will display information about each route. For more verbose output, add --debug flag. It will enable build output like rewrite, redirects, and headers. 

Development

To start the application in development mode, simply run following command:

npx next dev

The application will start at http://localhost:3000. If we want to change the port from 3000 to 4000, add -p flag followed by 4000. To change the default hostname to IP address, we can do that with -H flag followed by local IP address. This can be useful for making the application available for other device on the network.

npx next dev -H 192.168.1.3

HTTPS for local development

We can use https for our local development server. It will help us in some case where secure connection is required like webhooks or authentication. Next.js generate a self-signed certificate. Execute following command:

npx next dev --experimental-https

We can also provide custom certificate and key. Use following flags and execute the command:

npx next dev --experimental-https --experimental-https-key ./certificates/localhost-key.pem --experimental-https-cert ./certificates/localhost.pem

It will get work on local development only and not in production.

Production

We can run production server in local. It will help us to check and verify the functionality of the application. It will run the way it will run in production server. In may depend on the configuration of the server and local machine.

npx next start 

We can customize the default port by -p flag.

Next info

To display more details about the current project or application, we can execute following command:

npx next info

This information includes Operating System platform/arch/version, Binaries (Node.js, npm, Yarn, pnpm) and npm package versions (next, react, react-dom). It will help to debug the issue.

The output similar to:

Operating System:
  Platform: linux
  Arch: x64
  Version: #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023
Binaries:
  Node: 20.10.0
  npm: 10.2.3
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.0.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

We have completed the Next.js CLI available commands chapter.