If you have ever worked with a modern JavaScript project, you have probably seen commands like npm run dev
and npm run build
. They sound similar but the way they work under the hood is very different. Let’s break it down in plain language.
What happens when you run npm run dev
When you type npm run dev
, you are starting your project in development mode. What actually happens depends on the tools your project uses (for example Vite, Next.js, or React scripts), but the idea is the same across the board.
In development mode the tool does a few important things:
Starts a local server
This server runs on your machine, usually at something likehttp://localhost:3000
. It serves your app directly to your browser.Bundles or transforms code quickly
Instead of fully optimizing your JavaScript, CSS, and assets, the tool keeps things simple and fast. It might use techniques like lazy compilation so that only the files you touch get processed.Watches your files for changes
The real magic is the file watcher. The tool keeps an eye on all your source files. If you edit one, it detects the change instantly.Hot reload or live reload
Once the change is detected, the tool updates your browser without you needing to refresh manually. Depending on the setup, this can be a full page reload or a more advanced hot module replacement that swaps in just the updated code.
The result is a super fast feedback loop. You save a file, and your browser shows the update almost immediately. That is why npm run dev
feels smooth and responsive when you are coding.
Where are the files when running npm run dev
This is the part that sometimes confuses people. With npm run build
, you get a dist
or build
folder that contains the final static files. With npm run dev
, you will not see such a folder.
Here is why:
The development server does not write files to disk.
Instead it keeps everything in memory.
When your browser requests a file, the dev server compiles or transforms it on the fly and serves it directly.
That is why you cannot open a dist
folder during development. The files only “exist” inside the running server process. As soon as you stop the server, those temporary in-memory files are gone.
This approach is faster because the tool does not spend time saving and organizing files on your disk each time you make a change. It just streams the updated code straight to your browser.
How npm run build
is different
npm run build
is not about speed. It is about getting your project ready for the real world.
When you run npm run build
, your tool:
Processes all your files once
It takes every piece of code, styles, and assets and prepares them for browsers.Optimizes the output
It minimizes and compresses JavaScript and CSS, splits the code into chunks, removes unused parts, and makes sure everything is as small and efficient as possible.Outputs static files
Instead of running a live server, it creates a folder (often calleddist
orbuild
) filled with plain HTML, CSS, and JavaScript files. These are what you actually deploy to a hosting service or a production server.
Putting it simply
npm run dev
= quick, live updating environment for developers, files live in memory, nodist
foldernpm run build
= slow, optimized output for production deployment, files are written into adist
folder
Think of it like this. Development mode is like cooking with ingredients laid out on the counter where you can taste and adjust instantly. Build mode is like packaging the finished meal in a sealed container ready to be served.
If you’ve ever struggled with repetitive tasks, obscure commands, or debugging headaches, this platform is here to make your life easier. It’s free, open-source, and built with developers in mind.
👉 Explore the tools: FreeDevTools
👉 Star the repo: freedevtools
Top comments (0)