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
To run your locally installed version of Prettier, prefix the command with npx, yarn exec, pnpm exec, or bunx, i.e.
🌐
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')"
Discussions

How to run prettier check ?
Then, you can install it using npm install prettier inside the project directory, or install it globally on your computer using npm install -g prettier. To run prettier on your current directory use npx prettier . More on github.com
🌐 github.com
1
1
node.js - How to configure prettier to check all files with a specific extension - Stack Overflow
I have installed prettier via yarn add prettier I would like prettier to only format typescript code (I am developing AWS CDK project, there is no src folder by convention & there could be More on stackoverflow.com
🌐 stackoverflow.com
Format your code using prettier without null-ls! Just vanilla vim
:h formatprg may be more complicated to setup but it comes in handily because it lets you to use formatters with motions using gq which is nice if you don’t want to format the whole file every time More on reddit.com
🌐 r/neovim
18
52
July 2, 2023
node.js - npx - what does the `@` do in `npx prettier` vs `npx prettier@2`? - Stack Overflow
I'm familiar with node_modules/.bin and the npx tool. I've recently noticed one of our configs runs: npx prettier@2 Which actually produces different output from npx prettier It seems like pretti... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Fishtank
getfishtank.com › insights › running-prettier-from-the-command-line
Running Prettier from the Command Line | Fishtank
March 21, 2023 - Now format all files with Prettier by running - npm run format in your terminal. 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 .
🌐
GitHub
github.com › alshedivat › al-folio › discussions › 2623
How to run prettier check ? · alshedivat/al-folio · Discussion #2623
"Then, you can install it using npm install prettier inside the project directory, or install it globally on your computer using npm install -g prettier. To run prettier on your current directory use npx prettier . --write." Works for me.
Author   alshedivat
🌐
opencode
opencode.ai › docs › config
Config | OpenCode
3 days ago - "custom-prettier": { "command": ["npx", "prettier", "--write", "$FILE"], "environment": { "NODE_ENV": "development" }, "extensions": [".js", ".ts", ".jsx", ".tsx"] } } } Learn more about formatters here. By default, opencode allows all operations without requiring explicit approval.
🌐
npm
npmjs.com › package › prettier
prettier - npm
January 21, 2026 - Prettier is an opinionated code formatter. Latest version: 3.8.1, last published: a month ago. Start using prettier in your project by running `npm i prettier`. There are 20147 other projects in the npm registry using prettier.
      » npm install prettier
    
Published   Jan 21, 2026
Version   3.8.1
Author   James Long
Find elsewhere
🌐
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.
🌐
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.
🌐
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:
🌐
Prettier
prettier.io › blog › 2023 › 11 › 30 › cli-deep-dive
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:
🌐
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 2, 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!

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.

🌐
Prettier
prettier.io › docs › configuration
Configuration File · Prettier
A "prettier" key in your package.json, or package.yaml file.
🌐
Prettier
prettier.io › docs › watching-files
Watching For Changes · Prettier
You can have Prettier watch for changes from the command line by using onchange. For example: npx onchange "**/*" -- npx prettier --write --ignore-unknown {{changed}}
🌐
GitHub
github.com › tailwindlabs › prettier-plugin-tailwindcss › issues › 270
vscode prettier formatter doesn't match `npx prettier` · Issue #270 · tailwindlabs/prettier-plugin-tailwindcss
May 22, 2024 - module.exports = { plugins: ['prettier-plugin-tailwindcss'], tailwindFunctions: ['cn'], tailwindConfig: './tailwind.config.ts', semi: true, trailingComma: 'all', singleQuote: true, printWidth: 120, tabWidth: 2, }; When i run npx prettier --write it sorts the classes in a different order then when i use the prettier formatter in vscode (option + shift + f) Reactions are currently unavailable ·
Published   May 22, 2024
🌐
Reddit
reddit.com › r/vscode › prettier not working from the command palette
r/vscode on Reddit: Prettier not working from the Command Palette
March 20, 2023 -

Hi there,

I'm using VS Code on Windows 11, and I have installed Prettier. However, I can only use it from the terminal.

If I execute npx Prettier --write dom.html in the terminal, it works fine.

If I go to the Command Palette and choose Format Document, the following error appears in the output:

["ERROR" - 10:38:49 AM] Invalid prettier configuration file detected.
["ERROR" - 10:38:49 AM] ENOENT: no such file or directory, open 'c:\Users\ivanf\Dropbox\dev\FrontEndBootCamp - Exercises\firstjs\ C:\Users\ivanf\AppData\Roaming\npm\prettier'
Error: ENOENT: no such file or directory, open 'c:\Users\ivanf\Dropbox\dev\FrontEndBootCamp - Exercises\firstjs\ C:\Users\ivanf\AppData\Roaming\npm\prettier'

To make it more clear,

c:\Users\ivanf\Dropbox\dev\FrontEndBootCamp - Exercises\firstjs\ is the project folder, and \Users\ivanf\AppData\Roaming\npm\prettier is where prettier is installed.

So it seems that in some configuration file the wrong path "PROJECT_FOLDER PRETTIER_HOME" is formed.

Unfortunately, I cannot locate such file, and I cannot understand why it works when called from the terminal.

Any advice or hints? Thank you in advance, Ivan.

🌐
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 src/App.js.