First, pick your favorite Javascript based Pretty Print/Beautifier. I prefer the one at http://jsbeautifier.org/, because it's what I found first. Downloads its file https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify.js

Second, download and install The Mozilla group's Java based Javascript engine, Rhino. "Install" is a little bit misleading; Download the zip file, extract everything, place js.jar in your Java classpath (or Library/Java/Extensions on OS X). You can then run scripts with an invocation similar to this

java -cp js.jar org.mozilla.javascript.tools.shell.Main name-of-script.js

Use the Pretty Print/Beautifier from step 1 to write a small shell script that will read in your javascript file and run it through the Pretty Print/Beautifier from step one. For example

//original code    
(function() { ... js_beautify code ... }());

//new code
print(global.js_beautify(readFile(arguments[0])));

Rhino gives javascript a few extra useful functions that don't necessarily make sense in a browser context, but do in a console context. The function print does what you'd expect, and prints out a string. The function readFile accepts a file path string as an argument and returns the contents of that file.

You'd invoke the above something like

java -cp js.jar org.mozilla.javascript.tools.shell.Main beautify.js file-to-pp.js

You can mix and match Java and Javascript in your Rhino run scripts, so if you know a little Java it shouldn't be too hard to get this running with text-streams as well.

Answer from Alan Storm on Stack Overflow
🌐
npm
npmjs.com › package › js-beautify
js-beautify - npm
February 27, 2025 - The above install the latest stable release. To install beta or RC versions: ... The beautifier can be added on your page as web library. JS Beautifier is hosted on two CDN services: cdnjs and rawgit.
      » npm install js-beautify
    
Published   Feb 27, 2025
Version   1.15.4
Author   Einar Lielmanis
🌐
GitHub
github.com › beautifier › js-beautify
GitHub - beautifier/js-beautify: Beautifier for javascript · GitHub
You may install the NPM package js-beautify. When installed globally, it provides an executable js-beautify script.
Starred by 9K users
Forked by 1.4K users
Languages   JavaScript 42.8% | HTML 35.9% | Python 15.5% | Mustache 2.7% | Shell 2.6% | Makefile 0.3% | CSS 0.2%
🌐
Beautifier
beautifier.io
JS Beautifier
Beautify plugin (github) by HookyQR for the Visual Studio Code IDE, ... Netbeans jsbeautify plugin by Drew Hamlett (github).
🌐
Kali Linux Tools
en.kali.tools
JS Beautifier - Penetration Testing Tools
sudo pacman -R python-jsbeautifier sudo pacman -S npm sudo npm -g install js-beautify js-beautify -h
🌐
SourceForge
sourceforge.net › projects › js-beautifier.mirror
JS Beautifier download | SourceForge.net
February 10, 2025 - Download JS Beautifier for free. Beautifier for javascript. This little beautifier will reformat and re-indent bookmarklets, ugly JavaScript, unpack scripts packed by Dean Edward’s popular packer, as well as partly deobfuscate scripts processed by the npm package javascript-obfuscator.
🌐
Unibeautify
unibeautify.com › docs › beautifier-js-beautify
JS-Beautify Beautifier · Unibeautify
JS-Beautify beautifier for Unibeautify · Install with npm: npm install --save-dev js-beautify unibeautify @unibeautify/beautifier-js-beautify · Or with yarn: yarn add --dev js-beautify unibeautify @unibeautify/beautifier-js-beautify · Add ...
Top answer
1 of 10
76

First, pick your favorite Javascript based Pretty Print/Beautifier. I prefer the one at http://jsbeautifier.org/, because it's what I found first. Downloads its file https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify.js

Second, download and install The Mozilla group's Java based Javascript engine, Rhino. "Install" is a little bit misleading; Download the zip file, extract everything, place js.jar in your Java classpath (or Library/Java/Extensions on OS X). You can then run scripts with an invocation similar to this

java -cp js.jar org.mozilla.javascript.tools.shell.Main name-of-script.js

Use the Pretty Print/Beautifier from step 1 to write a small shell script that will read in your javascript file and run it through the Pretty Print/Beautifier from step one. For example

//original code    
(function() { ... js_beautify code ... }());

//new code
print(global.js_beautify(readFile(arguments[0])));

Rhino gives javascript a few extra useful functions that don't necessarily make sense in a browser context, but do in a console context. The function print does what you'd expect, and prints out a string. The function readFile accepts a file path string as an argument and returns the contents of that file.

You'd invoke the above something like

java -cp js.jar org.mozilla.javascript.tools.shell.Main beautify.js file-to-pp.js

You can mix and match Java and Javascript in your Rhino run scripts, so if you know a little Java it shouldn't be too hard to get this running with text-streams as well.

2 of 10
64

UPDATE April 2014:

The beautifier has been rewritten since I answered this in 2010. There is now a python module in there, an npm Package for nodejs, and the jar file is gone. Please read the project page on github.com.

Python style:

$ pip install jsbeautifier

NPM style:

$ npm -g install js-beautify

to use it (this will return the beatified js file on the terminal, the main file remains unchanged):

$ js-beautify file.js

To make the changes take effect on the file, you should use this command:

$ js-beautify -r file.js

Original answer

Adding to Answer of @Alan Storm

the command line beautifier based on http://jsbeautifier.org/ has gotten a bit easier to use, because it is now (alternatively) based on the V8 javascript engine (c++ code) instead of rhino (java-based JS engine, packaged as "js.jar"). So you can use V8 instead of rhino.

How to use:

download jsbeautifier.org zip file from http://github.com/einars/js-beautify/zipball/master

(this is a download URL linked to a zip file such as http://download.github.com/einars-js-beautify-10384df.zip)

old (no longer works, jar file is gone)

java -jar js.jar  name-of-script.js

new (alternative)

install/compile v8 lib FROM svn, see v8/README.txt in above-mentioned zip file

./jsbeautify somefile.js

-has slightly different command line options than the rhino version,

-and works great in Eclipse when configured as an "External Tool"

🌐
Homebrew
formulae.brew.sh › formula › js-beautify
js-beautify — Homebrew Formulae
brew install js-beautify · JavaScript, CSS and HTML unobfuscator and beautifier · https://beautifier.io · License: MIT · Development: Pull requests · Formula JSON API: /api/formula/js-beautify.json · Formula code: js-beautify.rb on GitHub ...
🌐
GitHub
github.com › beautifier › js-beautify › blob › main › README.md
js-beautify/README.md at main · beautifier/js-beautify
December 9, 2024 - You may install the NPM package js-beautify. When installed globally, it provides an executable js-beautify script.
Author   beautifier
Find elsewhere
🌐
UNPKG
unpkg.com › browse › js-beautify@0.4.2 › README.md
js-beautify/README.md
As with the Python script, the beautified result is sent to `stdout` unless otherwise configured. ```bash $ npm -g install js-beautify $ js-beautify foo.js ``` You can also use `js-beautify` as a `node` library (install locally, the `npm` default): ```bash $ npm install js-beautify ``` ```js ...
🌐
GitHub
github.com › TALLStackHub › js-beautify
GitHub - TALLStackHub/js-beautify · GitHub
npm install js-beautify-with-blade · Beside all the usage examples you can found at the orignal js-beautify. You can use this package as blade beautifier · npx html-beautify resources/views/**/*.blade.php -r · run the above command in your ...
Author   TALLStackHub
🌐
PyPI
pypi.org › project › jsbeautifier
jsbeautifier · PyPI
Beautify, unpack or deobfuscate JavaScript. Handles popular online obfuscators. ... Author: Liam Newman, Einar Lielmanis, et al. ... Download the file for your platform. If you're not sure which to choose, learn more about installing packages. ... Filter files by name, interpreter, ABI, and platform. If you're not sure about the file name format, learn more about wheel file names. ... Details for the file jsbeautifier-1.15.4.tar.gz.
      » pip install jsbeautifier
    
Published   Feb 27, 2025
Version   1.15.4
🌐
GitHub
github.com › Unibeautify › beautifier-js-beautify
GitHub - Unibeautify/beautifier-js-beautify: JS-Beautify beautifier for Unibeautify · GitHub
JS-Beautify beautifier for Unibeautify · npm install --global @unibeautify/beautifier-js-beautify ·
Author   Unibeautify
🌐
cdnjs
cdnjs.com › home › libraries › js-beautify
js-beautify - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers
https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautifier.js · https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautifier.min.js · https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify-css.js · https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.4/beautify-css.min.js ·
🌐
GitHub
github.com › yasuyk › web-beautify
GitHub - yasuyk/web-beautify: Format HTML, CSS and JavaScript/JSON by js-beautify
js-beautify installed by typing: npm -g install js-beautify
Starred by 223 users
Forked by 21 users
Languages   Emacs Lisp 82.2% | Makefile 17.8% | Emacs Lisp 82.2% | Makefile 17.8%
🌐
Package Control
packagecontrol.io › packages › Javascript Beautify
Javascript Beautify - Packages - Package Control
Project Deprecated , since that I am busy with another project and most of the time I use atom, the project deprecated , andbody who use js beautify can use https://github.com/jdc0589/JsFormat
🌐
npm
npmjs.com › package › @types › js-beautify
@types/js-beautify - npm
November 7, 2023 - npm install --save @types/js-beautify · This package contains type definitions for js-beautify (https://github.com/beautify-web/js-beautify/). Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/js-beautify.
      » npm install @types/js-beautify
    
🌐
EasyRetro
easyretro.io › tools › js-beautifier
JS Beautifier (Simple and Easy) | EasyRetro
Is your JavaScript code becoming hard to maintain? Try our free JS Beautifier!
🌐
JSON Formatter
jsonformatter.org › jsbeautifier
Best JSBeautifier to beautify / format JavaScript
This Javascript Beautifier that supports indentation levels: 2 tab spaces, 3 tab spaces, and 4 tab spaces. Download JS, once it's formatted, created or modified and this js file can be opened in Sublime, VSCode, and Notepad++ alternative.