For *.ts files:

npx prettier 'src/**/*.ts' --write

If you want target other file extensions:

npx prettier 'src/**/*.{js,ts,mjs,cjs,json}' --write
Answer from Tiago Bértolo on Stack Overflow
🌐
Prettier
prettier.io › docs › cli
CLI · Prettier
If you're worried that Prettier will change the correctness of your code, add --debug-check to the command. This will cause Prettier to print an error message if it detects that code correctness might have changed.
🌐
Prettier
prettier.io › docs › install
Install · Prettier
In addition to running Prettier from the command line (prettier --write), checking formatting in CI, and running Prettier from your editor, many people like to run Prettier as a pre-commit hook as well. This makes sure all your commits are formatted, without having to wait for your CI build to finish. 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')"
🌐
GitHub
github.com › alshedivat › al-folio › discussions › 2623
How to run prettier check ? · alshedivat/al-folio · Discussion #2623
Then, you can install it using ... Another option (if you want to just check what went wrong) is to check the failed action in your GitHub repo....
Author   alshedivat
🌐
Scarb
docs.swmansion.com › setup-ci › docs › workflows › prettier
Prettier check | npx setup-ci
Learn more about Prettier: prettier.io · npx setup-ci --preset --prettier · Below you can find detailed information about what the script does with your project when generating Prettier check workflow.
🌐
Fishtank
getfishtank.com › insights › running-prettier-from-the-command-line
Running Prettier from the Command Line | Fishtank
This command will pick up “format” inside “script” in your project’s package. JSON file. npm run format · Alternatively; NPM · npx prettier --write . YARN · yarn prettier --write .
🌐
Medium
jareddesign.medium.com › making-nx-format-check-prettier-dc34924d214d
Making nx format:check Prettier. The primary issue with nx format:check… | by Jared Christensen | Medium
November 12, 2023 - #!/bin/bash # ANSI color codes RED='\033[0;31m' GREEN='\033[0;32m' CYAN='\033[0;36m' NC='\033[0m' SEPARATOR="----------------------------------------" # Run nx pretty-format-check and capture the output output=$(nx format:check 2>&1) # Capture the exit status result=$? # Check if the command failed if [ $result -ne 0 ]; then echo -e "${RED}$SEPARATOR" echo -e "Error: Formatting check failed" echo -e "$SEPARATOR${NC}" echo -e "Files with formatting issues:\n$output\n" echo -e "${CYAN}Please run 'npx nx format:write' to fix formatting issues." exit $result fi echo -e "${GREEN}Formatting check passed successfully.${NC}"
🌐
Prettier
prettier.io › blog › 2023 › 11 › 30 › cli-deep-dive.html
Prettier's CLI: A Performance Deep Dive · Prettier
November 30, 2023 - PRETTIER_LEGACY_CLI=1 prettier . --check · You can also try it via npx, though npx itself is pretty slow:
Find elsewhere
🌐
Simon Willison
til.simonwillison.net › github-actions › prettier-github-actions
Using Prettier to check JavaScript code style in GitHub Actions | Simon Willison’s TILs
The npx prettier --check 'datasette/static/*[!.min].js' line ensures that prettier is run in "check" mode (which fails the tests if a matching file does not conform to the formatting rules) - it checks any .js file in the datasette/static folder ...
🌐
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. If you want to check before manual formatting, enter the command npx prettier --check .
🌐
E18e
e18e.dev › blog › prettier-speed-up.html
Improving Prettier performance with the new CLI | e18e
$ time npx prettier --check . Checking formatting... All matched files use Prettier code style! npx prettier --check . 34.24s user 7.39s system 141% cpu 29.407 total $ PRETTIER_EXPERIMENTAL_CLI=1 time npx prettier . --check Checking formatting... All matched files use Prettier code style!
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.

🌐
GitHub
github.com › prettier › prettier-cli
GitHub - prettier/prettier-cli: A faster CLI for Prettier.
prettier . --check # Like before, but faster · You can also try it via npx, though npx itself is pretty slow: npx prettier@next .
Starred by 40 users
Forked by 10 users
Languages   JavaScript 50.9% | TypeScript 48.9%
🌐
npm
npmjs.com › package › @prettier › cli
prettier/cli
prettier . --check # Like before, but faster · You can also try it via npx, though npx itself is pretty slow: npx prettier@next . --check · none · npm i @prettier/cli · github.com/prettier/prettier-cli · github.com/prettier/prettier-cli#readme ...
      » npm install @prettier/cli
    
Published   Nov 17, 2025
Version   0.10.0
🌐
npm
npmjs.com › package › prettier-check
prettier-check - npm
Check that all files match prettier code style.. Latest version: 2.0.0, last published: 8 years ago. Start using prettier-check in your project by running `npm i prettier-check`. There are 9 other projects in the npm registry using prettier-check.
      » npm install prettier-check
    
Published   Sep 24, 2017
Version   2.0.0
Author   pomber
🌐
Layer5
discuss.layer5.io › meshery
While making the commit i am getting error related to npx prettier - Meshery - Layer5 Community Forum
October 2, 2023 - I have shared the error while I am getting the commit locally. Please help. git commit -s -m “Merge branch master of GitHub - meshery/meshery: Meshery, the cloud native manager” [STARTED] Preparing lint-staged… [SUCCE…
🌐
Reddit
reddit.com › r/neovim › format your code using prettier without null-ls! just vanilla vim
r/neovim on Reddit: Format your code using prettier without null-ls! Just vanilla vim
July 1, 2023 -

I've been trying to use as neovim as vanilla possible to expand my horizon and one of the coolest and unknown features out here must be the filter (:!) command. Basically, you can (optionally) redirect part of your buffer as stdin to a shell command which writes it back into your buffer!

As an example, this one way how you could format your code using prettier:

:%!npx prettier --stdin-filepath %

Explanation:

  • The % before the ! is the range, ie, which part of your buffer do you want to redirect to the command? % means everything, but you could also say for example :.!npx prettier ... where the . would be just the current line, or make a visual selection and write :'<,'>!npx prettier ....

  • The ! is called filter by the vim docs, it calls a shell command

  • Next comes the command itself, the first part is pretty self explanatory. I don't have prettier installed globally so I use npx. You have to pass the --stdin-filepath option, otherwise it won't read your buffer, but the file content (which can differ from your buffer if, for example, you haven't saved your buffer yet). The second % means, in the context of the shell command, "the current file name". (And another cool trick: you can expand it using <c-a>)

That's it, you can use this with any shell command! The beauty of the unix philosophy...

Of course you could also map this to some keybinding.

If you know other cool and hidden tricks of vim, please share them in the comments!

🌐
GitHub
github.com › prettier › prettier › issues › 6280
How do I use the CLI to fix all files? · Issue #6280 · prettier/prettier
July 9, 2019 - If I try prettier --check "*" or prettier --check NOTHING then Prettier seems to completely ignore the .prettierignore file.
Published   Jul 09, 2019
🌐
npm
npmjs.com › package › prettier
prettier - npm
Prettier can be run in your editor on-save, in a pre-commit hook, or in CI environments to ensure your codebase has a consistent style without devs ever having to post a nit-picky comment on a code review ever again!
      » npm install prettier
    
Published   Jan 21, 2026
Version   3.8.1
Author   James Long
🌐
Holt
react-v8.holt.courses › lessons › js-tools › prettier
Prettier – Complete Intro to React v8
Either install Prettier globally ... 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 src/App.js. Go check src/App.js and see it has been ...