What’s the difference between npm run dev, npm run build and npm run start in Next.js?
Ever wondered what goes different when we enter npm run dev and npm run start in console to run our next.js app? Here we have some answers
Short Answer
npm run dev
is used for development with features like hot module replacement, npm run build
is used to create an optimized production build, and npm run start
is used to run the Next.js server in production mode after the build process is completed.
If you go to the next.js official webpage, this is what they have to say about the difference between dev and build scripts
These scripts refer to the different stages of developing an application:
dev
: runsnext dev
to start Next.js in development mode.
build
: runsnext build
to build the application for production usage.
start
: runsnext start
to start a Next.js production server.
So, basicall In Next.js, npm run dev
, npm run build
, and npm run start
are three different commands used for various purposes during the development and deployment process. Here's the difference between them: