What's the Difference Between npm start and npm build? A Complete Guide for Developers

6 min readArticle
Authors
What's the Difference Between npm start and npm build? A Complete Guide for Developers

In short: npm start runs your app (usually a development server or a production server, depending on the framework), while npm run build produces an optimized production bundle ready to deploy. The exact behavior comes from your project’s package.json scripts.

TL;DR

  • npm start: Executes the "start" script in package.json. Commonly spins up a dev server with HMR/Fast Refresh. If there’s no script, npm defaults to node server.js.
  • npm run build: Executes the "build" script. Typically bundles/minifies your code into a build or dist directory for production.

Under the Hood: npm Scripts

npm doesn’t “know” what start or build should do—it simply runs the commands you define in package.json. That’s why behavior can differ across projects. Conventions have emerged, but always check your scripts to be sure.

How Popular Frameworks Map These Commands

React (CRA/Vite-like toolchains)

  • npm start: Launches a development server with warnings and HMR/Fast Refresh.
  • npm run build: Produces a minified, production-optimized bundle.

Next.js

  • npm run dev: next dev (development server).
  • npm run build: next build (create production build).
  • npm start: next start (serve the production build).

Environments & Optimizations

Many toolchains automatically set NODE_ENV to development for dev servers and to production for builds. Production builds enable optimizations (minification, dead-code elimination, code splitting) and disable dev-only warnings.

Example package.json

{
"scripts": {
    "dev": "vite",             // or: "react-scripts start" / "next dev"
    "build": "vite build",     // or: "react-scripts build" / "next build"
    "start": "node server.js"  // or: "vite preview" / "next start"
}
}

Your project might differ—always inspect package.json to confirm what each script actually runs.

Key Differences: Dev vs Production

Aspect npm start (Dev Server) npm run build (Production Bundle)
Goal Fast iteration, HMR/Fast Refresh Optimized output for deployment
Optimizations Minimal; dev warnings enabled Minify, tree-shake, split chunks
Performance focus Developer feedback loop User load time & runtime performance
Environment Usually NODE_ENV=development Usually NODE_ENV=production

How to Test Your Production Build Locally

Don’t just run start and assume production will behave the same. Build and then serve the build:

  • Next.js: npm run buildnpm start.
  • React (CRA/Vite): npm run build → serve the build/dist folder with a static server (e.g., npx serve -s build or your hosting preview).

If something looks different in production, check your build config, environment variables, asset paths, and CSS bundling.

Quick FAQ

Is npm start the same as npm run start?

Yes—both run the start script. The special case is: if no script is defined, npm start falls back to node server.js.

Why do these commands behave differently across projects?

Because they’re just script names—the underlying commands are project-defined. Conventions help, but always read your package.json.

Next.js: dev vs start?

dev runs the development server; start serves the production build created by build.


Bottom line: use start to run the app (typically in development), use build to produce the assets you deploy. Always verify what your scripts do and test the production build locally before shipping.