npx will cause a package to be downloaded and execute bin scripts provided by that package. The command npx prettier will cause the latest version of the prettier to be downloaded and the file ./bin/prettier.js will be executed.

npx also allows you specify which specific semantic version you want to download with the @ notation. So npx prettier runs latest, but npx prettier@2 will still run only version 2 even when prettier updates to a new major version.

See npx package docs:

npx [options] <command>[@version] [command-arg]...

and

-p, --package <package> - define the package to be installed. This defaults to the value of <command>. This is only needed for packages with multiple binaries if you want to call one of the other executables, or where the binary name does not match the package name. If this option is provided <command> will be executed as-is, without interpreting @version if it's there. Multiple --package options may be provided, and all the packages specified will be installed.


A somewhat deeper look at your question makes things a little bit weirder though. I'm unsure why you get different results when you run both commands, they should be equivalent (right now at least since 2 is the current major version).

Try printing the version string with both and see if you get a difference, that might show some additional details

npx prettier --version
npx prettier@2 --version

Both give me the same string, but that might be different depending on your cache or config.

Answer from zero298 on Stack Overflow
🌐
Prettier
prettier.io › docs › install
Install · Prettier
For example, you can do the following to have Prettier run before each commit: ... npm install --save-dev husky lint-staged npx husky init node --eval "fs.writeFileSync('.husky/pre-commit','npx lint-staged\n')"
🌐
Prettier
prettier.io › docs › cli.html
CLI · Prettier
To run your locally installed version of Prettier, prefix the command with npx, yarn exec, pnpm exec, or bunx, i.e.
🌐
GitHub
github.com › prettier › eslint-config-prettier
GitHub - prettier/eslint-config-prettier: Turns off all rules that are unnecessary or might conflict with Prettier. · GitHub
env ESLINT_CONFIG_PRETTIER_NO_DEPRECATED=true npx eslint-find-rules --deprecated index.js
Starred by 5.9K users
Forked by 262 users
Languages   JavaScript
🌐
npm
npmjs.com › package › @6river › prettier-config
@6river/prettier-config - npm
Add ignored directories and files to .prettierignore. Most of the time, this can be done with cp .gitignore .prettierignore. Run the following command, adding or removing file extensions from the list to meet your needs: npx prettier --write '**/*.{js,ts,md,json,yml,yaml,css,scss,less,graphql,mdx,jsx,tsx}'
      » npm install @6river/prettier-config
    
Published   Aug 16, 2023
Version   1.2.28
Top answer
1 of 1
2

npx will cause a package to be downloaded and execute bin scripts provided by that package. The command npx prettier will cause the latest version of the prettier to be downloaded and the file ./bin/prettier.js will be executed.

npx also allows you specify which specific semantic version you want to download with the @ notation. So npx prettier runs latest, but npx prettier@2 will still run only version 2 even when prettier updates to a new major version.

See npx package docs:

npx [options] <command>[@version] [command-arg]...

and

-p, --package <package> - define the package to be installed. This defaults to the value of <command>. This is only needed for packages with multiple binaries if you want to call one of the other executables, or where the binary name does not match the package name. If this option is provided <command> will be executed as-is, without interpreting @version if it's there. Multiple --package options may be provided, and all the packages specified will be installed.


A somewhat deeper look at your question makes things a little bit weirder though. I'm unsure why you get different results when you run both commands, they should be equivalent (right now at least since 2 is the current major version).

Try printing the version string with both and see if you get a difference, that might show some additional details

npx prettier --version
npx prettier@2 --version

Both give me the same string, but that might be different depending on your cache or config.

🌐
DEV Community
dev.to › bokub › how-to-properly-set-up-prettier-in-less-than-2-minutes-2ld0
How to properly set up Prettier in less than 2 minutes - DEV Community
July 5, 2022 - # With npm npx husky-init npm i -D pretty-quick npx husky set .husky/pre-commit "npx pretty-quick --staged" # With yarn npx husky-init yarn add -D pretty-quick yarn husky set .husky/pre-commit "npx pretty-quick --staged" That’s it ! You will now see this kind of message every time you commit something: The main differences between Prettier and ESLint are the following: ESLint is a linter: it can detect errors in your code and also format your code if you configure it correctly
🌐
Stack Overflow
stackoverflow.com › questions › 76038730 › vscode-prettier-setting-configs-to-match-npx-standard-fix
visual studio code - VSCode Prettier setting configs to match "npx standard --fix" - Stack Overflow
When running the npx standard --fix command, things like end of array commas, newlining, etc. are different from what is automated when saving a .js/.css file using Prettier. ... { "extends": [ "standard", // https://github.com/standard/eslint-config-standard#usage "plugin:prettier/recommended" // required by eslint-plugin-prettier, must be last; auto-configures prettier ], }
🌐
GitHub
btholt.github.io › complete-intro-to-react-v5 › eslint-prettier
npm, ESLint & Prettier
Either install Prettier globally npm install --global prettier or replace when I run prettier with (from the root of your project) npx prettier. From there, run prettier script.js. This will output the formatted version of your file. If you want to actually write the file, run prettier --write ...
Find elsewhere
🌐
npm
npmjs.com › package › @rocketmakers › prettier-config
@rocketmakers/prettier-config - npm
Package to return prettier config based on a set of internally defined standards.
      » npm install @rocketmakers/prettier-config
    
Published   Jul 18, 2024
Version   2.1.0
Author   Product team
🌐
npm
npmjs.com › package › eslint-config-prettier
eslint-config-prettier - npm
env ESLINT_CONFIG_PRETTIER_NO_DEPRECATED=true npx eslint-find-rules --deprecated index.js
      » npm install eslint-config-prettier
    
Published   Jul 18, 2025
Version   10.1.8
Author   Simon Lydell
🌐
GitHub
github.com › u3u › prettier-config
GitHub - u3u/prettier-config: 🎨 The most perfect Prettier config
pnpm add lint-staged simple-git-hooks ... = extendConfig({ printWidth: 80, }); You can place the config file in the user's home directory as the default config to format all files....
Author   u3u
🌐
Holt
react-v8.holt.courses › lessons › js-tools › prettier
Prettier – Complete Intro to React v8
Either install Prettier globally npm install --global prettier or replace when I run prettier with (from the root of your project) npx prettier. From there, run prettier src/App.js. This will output the formatted version of your file. If you want to actually write the file, run prettier --write ...
🌐
Expo Documentation
docs.expo.dev › integrations › tools › using eslint and prettier
Using ESLint and Prettier - Expo Documentation
2 weeks ago - Note: In the above configuration, you can use "prettier/prettier": "warn" if you prefer these formatting issues as warnings instead of errors. Now, when you run npx expo lint, anything that is not aligned with Prettier formatting will be caught as an error.
🌐
Bitstack
blog.bitsrc.io › add-prettier-to-your-project-d7e91ac03d05
How to Add Prettier to a Project. Format code in your project with… | by Ivo Nederlof | Bits and Pieces
March 4, 2025 - Create a file named .prettierignore in the root of you project. Add files or folders you want to to ignore, for example: ./dist · In your package.json, add "format": "npx prettier --write ." in the scripts section: ... "version": "0.0.0", "scripts": { "start": "node index.js", "format": "npx prettier --write ."
🌐
GitHub
github.com › bokub › prettier-config
GitHub - bokub/prettier-config: 💜 My personal Prettier config & workflow
# With npm npm i -D prettier @bokub/prettier-config # With yarn yarn add -D prettier @bokub/prettier-config ... npx husky init echo "npx lint-staged --concurrent false" > .husky/pre-commit npm pkg set "lint-staged.*"="prettier --write --ignore-unknown"
Author   bokub
🌐
Fishtank
getfishtank.com › insights › running-prettier-from-the-command-line
Running Prettier from the Command Line | Fishtank
For Prettier to run in your terminal, you must install Prettier in your project’s local dependencies. ... After the installation is complete, create an empty config file.
🌐
GoodRequest
goodrequest.com › blog › code-formatting-using-the-prettier-tool
How to format code with Prettier tool step-by-step guide | GoodRequest
July 14, 2023 - Prettier provides the ability to format the entire project manually with a command npx prettier --write.
🌐
Scarb
docs.swmansion.com › setup-ci › docs › workflows › prettier
Prettier check | npx setup-ci
npx setup-ci --preset --prettier · Below you can find detailed information about what the script does with your project when generating Prettier check workflow. prettier (dev) The following diagram represents the flow of the Prettier check ...
🌐
DEV Community
dev.to › receter › how-to-install-prettier-in-your-codebase-and-vscode-4c19
How to Install Prettier in Your Codebase and VSCode - DEV Community
August 14, 2024 - Here is an example .prettierignore to skip all HTML files: ... Before continuing with formating the whole codebase, commit your changes. I also recommend merging all open pull requests, as a lot of files will be affected. Now run this command in the root folder of your project to format all files: ... ℹ️ using npx here ensures that the locally installed version of Prettier is executed.