Sometimes, we want to beautify JavaScript code using command line.
In this article, we’ll look at how to beautify JavaScript code using command line.
How to beautify JavaScript code using command line?
To beautify JavaScript code using command line, we can use prettier.
For instance, we run
npx prettier --single-quote --write --trailing-comma all "js/**/*.js"
to run prettier with npx to beautify JavaScript code in the js folder, including all child directories in it.
The --single-quote option formats strings with single quotes.
--write saves the formatting changes.
--trailing-comma add trailing commas to places that can have them like in the end of arrays and object literals.
Conclusion
To beautify JavaScript code using command line, we can use prettier.