Deploy Next.js application in production

How to generate a production version of the Next.js application

It is easy to deploy applications created with Next.js in a production environment. Add these 3 lines topackage.json scriptsection:

"scripts": {
  "dev": "next",
  "build": "next build",
  "start": "next start"

We usednpm run devUntil now,nextInstall the command locallynode_modules/next/dist/bin/next. This starts the development server and gives usSource mapwithHot code reinstallation, There are two very useful functions when debugging.

You can call the same command to build throughbuildMark by runningnpm run build. Then, you can use the same command to start the production application with the following commandstartMark by runningnpm run start.

These two commands are commands that we must call to successfully deploy the production version of the site locally. The production version is highly optimized and does not come with source maps and other things such as hot code reinstallation, which are not beneficial to our end users.

So let's create a production deployment of the application. Use the following command to build:

npm run build

The output of this command tells us some routes (/with/blogIs now rendered as static HTML, while/blog/[id]Will be provided by the Node.js backend.

Then you can runnpm run startStart the production server locally:

npm run start

Visitinghttp://localhost:3000The official version of the application will be shown to us locally.

Download mine for freeNext.js manual

More tutorials next: