Kamran Mushtaq
Back to Development Commands
Development Commands

npm run format

Added: July 17, 2026

Definition

npm run format runs a script named format from your project's package.json. It is commonly used to automatically format your code using tools like Prettier.

Example:

{ "scripts": { "format": "prettier --write ." } }

Running:

npm run format

is equivalent to:

prettier --write .

The Problem That Led to It

Before formatters, every developer wrote code differently—different spacing, indentation, quotes, and line breaks. Teams spent time arguing over code style and reviewing formatting instead of functionality.

What Problem It Solves

It automatically makes all code follow the same style, improving readability and reducing unnecessary changes in Git.

What Happens If Not Used

  • Inconsistent code style.
  • Harder code reviews.
  • More merge conflicts caused by formatting differences.

Easy Wording

It automatically cleans and organizes your code so everyone writes it the same way.

Layman Example

Like clicking "Format Paragraph" in Microsoft Word to make an entire document look neat.

Technical Example

Before:

const user={name:"Kami",age:20}

Run:

npm run format

After:

const user = { name: "Kami", age: 20, };

Limitation

It only changes how the code looks, not how it works. It won't fix bugs or improve logic.