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
🌐
Kali Linux Tools
en.kali.tools
JS Beautifier - Penetration Testing Tools
Homepage: https://beautifier.io/ ... MIT · The JS Beautifier package includes three tools: js-beautify – the main tool that improves the readability of JavaScript code, available in all JS Beautifier variants....
Main
JS Beautifier · JStillery · OllyDbg · Reverse · smali · TrID · UglifyJS · Valgrind · YARA · CaseFile · CutyCapt · dos2unix · Dradis · KeepNote · MagicTree · Metagoofil · Nipper-ng · pipal ·
All Programs
Tools for penetration testing and security audit · List of all available tools for penetration testing
Cheap VDS/VPS
Please click here if you are not redirected within a few seconds · You will be redirected in 3 seconds. If your browser does not automatically redirect you, please click here
🌐
GitHub
github.com › beautifier › js-beautify
GitHub - beautifier/js-beautify: Beautifier for javascript · GitHub
... To use js-beautify as a node library (after install locally), import and call the appropriate beautifier method for JavaScript (JS), CSS, or HTML. All three method signatures are beautify(code, options).
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%
🌐
Kali Linux Tools
en.kali.tools › all
python-jsbeautifier
Home / Tools / python-jsbeautifier · List of all available tools for penetration testing. Description: JavaScript unobfuscator and beautifier · Category: reversing webapp · Version: 1.15.1 · WebSite: https://github.com/beautify-web/js-beautify · Last Updated: 2024-02-21 ·
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"

🌐
Kali Linux Tools
en.kali.tools
JStillery - Penetration Testing Tools
It is not necessary to install the program on a computer, the author has created a page that can de-obfuscate JavaScript code: https://mindedsecurity.github.io/jstillery/ ... KaliTools April 10, 2021 beautifier for source code, Computer forensics, deobfuscation, JavaScript Reverse Engineering ...
🌐
PyPI
pypi.org › project › jsbeautifier
jsbeautifier · PyPI
JavaScript unobfuscator and beautifier.
      » pip install jsbeautifier
    
Published   Feb 27, 2025
Version   1.15.4
🌐
Command Not Found
command-not-found.com › js-beautify
command-not-found.com – js-beautify
JavaScript unobfuscator and beautifier · Maintainer: Sebastien Delafond <[email protected]> Homepage: https://github.com/beautify-web/js-beautify · Section: misc · All systems · curl cmd.cat/js-beautify.sh · Debian · apt-get install jsbeautifier · Ubuntu · apt-get install jsbeautifier · Arch Linux · pacman -S node-js-beautify · Kali Linux ·
🌐
Beautifier
beautifier.io
Online JavaScript beautifier
Chrome, in case the built-in CSS and javascript formatting isn't enough for you: — Quick source viewer by Tomi Mickelsson (github, blog), — Javascript and CSS Code beautifier by c7sky, — jsbeautify-for-chrome by Tom Rix (github), — Pretty Beautiful JavaScript by Will McSweeney — Stackoverflow Code Beautify by Making Odd Edit Studios (github).
🌐
OnWorks
onworks.net › home › software › app js beautifier
JS Beautifier
JS Beautifier
JS Beautifier free download and run online in OnWorks over Linux online like Ubuntu, Fedora, Debian, Kali Linux
Rating: 4 ​
Find elsewhere
🌐
Kali Linux Tools
en.kali.tools
de4js - Penetration Testing Tools
git clone https://github.com/lelinhtinh/de4js cd de4js bundle install · Installing Workbox CLI: sudo npm install workbox-cli --global · Server start: npm start · Or with a real-time usage output: npm run watch · De4js is now available in the web browser at: http://localhost:4000/de4js/ How to deobfuscate JavaScript code · How to see JavaScript code written using unprintable characters · JavaScript Attacks · UglifyJS (100%) JStillery (84.9%) JS Beautifier (84.9%) Binwalk (54.6%) Detect It Easy (54.6%) usbrip (RANDOM - 4.6%) KaliTools April 18, 2021 beautifier for source code, Computer forensics, deobfuscation, JavaScript, obfuscation Reverse Engineering Comments Off on de4js ·
🌐
OnWorks
onworks.net › home › software › linux › app js beautifier
JS Beautifier download for Linux
JS Beautifier download for Linux
JS Beautifier free download and run online in OnWorks over Linux online like Ubuntu, Fedora, Debian, Kali Linux
Rating: 4 ​
🌐
Repology
repology.org › project › js-beautify › packages
js-beautify packages - Repology
Kali Linux Rolling main · 1.15.3 (1.15.3-1) Maintainer: havard.f.aasen@pfft.no · Category: misc · Link(s): Package pageok · Upstream homepageredir, no IPv6 · MacPorts · 1.15.4 · Summary: JS beautifier written in Python · Maintainer: nomaintainer@macports.org ·
🌐
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
🌐
JSON Formatter
jsonformatter.org › b9e805
kali
This JSON online formatter can also work as JSON Lint. Use Auto switch to turn auto update on or off for beautification.
🌐
GitHub
github.com › psyrendust › js-prettify
GitHub - psyrendust/js-prettify: This little beautifier will reformat and reindent bookmarklets, ugly JavaScript, unpack scripts packed by Dean Edward’s popular packer, as well as deobfuscate scripts processed by [javascriptobfuscator.com](http://javascriptobfuscator.com/).
This is a copy of the original 1.4.0 repo (https://github.com/jonschlinkert/js-prettify) created by Jon Schlinkert. This is only for archiving purposes. This little beautifier will reformat and reindent bookmarklets, ugly JavaScript, unpack scripts packed by Dean Edward’s popular packer, as well as deobfuscate scripts processed by javascriptobfuscator.com.
Author   psyrendust
🌐
SourceForge
sourceforge.net › projects › js-beautifier.mirror
JS Beautifier download | SourceForge.net
This is an exact mirror of the JS Beautifier project, hosted at https://github.com/beautify-web/js-beautify.
🌐
GitHub
github.com › yasuyk › web-beautify
GitHub - yasuyk/web-beautify: Format HTML, CSS and JavaScript/JSON by js-beautify
(eval-after-load 'js2-mode '(add-hook 'js2-mode-hook (lambda () (add-hook 'before-save-hook 'web-beautify-js-buffer t t)))) ;; Or if you're using 'js-mode' (a.k.a 'javascript-mode') (eval-after-load 'js '(add-hook 'js-mode-hook (lambda () (add-hook 'before-save-hook 'web-beautify-js-buffer t t)))) (eval-after-load 'json-mode '(add-hook 'json-mode-hook (lambda () (add-hook 'before-save-hook 'web-beautify-js-buffer t t)))) (eval-after-load 'sgml-mode '(add-hook 'html-mode-hook (lambda () (add-hook 'before-save-hook 'web-beautify-html-buffer t t)))) (eval-after-load 'web-mode '(add-hook 'web-mode-hook (lambda () (add-hook 'before-save-hook 'web-beautify-html-buffer t t)))) (eval-after-load 'css-mode '(add-hook 'css-mode-hook (lambda () (add-hook 'before-save-hook 'web-beautify-css-buffer t t))))
Starred by 223 users
Forked by 21 users
Languages   Emacs Lisp 82.2% | Makefile 17.8% | Emacs Lisp 82.2% | Makefile 17.8%
🌐
GitHub
github.com › PortSwigger › js-beautifier
GitHub - PortSwigger/js-beautifier: Burp Suite JS Beautifier
Step 1- (Adding Libraries) Now under "Extender" tab, click on the "Options" tab; in "Java Environment" section, click on "Select folder ..." button and select the "libs" folder that contains "js.jar" and "rsyntaxtextarea.jar".
Starred by 5 users
Forked by 2 users
Languages   Java 59.7% | JavaScript 40.1% | HTML 0.2% | Java 59.7% | JavaScript 40.1% | HTML 0.2%
🌐
Richard512
richard512.github.io › jsbeautifier
Online JavaScript beautifier
Beautify, unpack or deobfuscate JavaScript and HTML, make JSON/JSONP readable, etc. All of the source code is completely free and open, available on GitHub under MIT licence, and we have a command-line version, python library and a node package as well. ... Chrome, in case the built-in CSS ...
🌐
GitHub
github.com › hmnd › js-beautify
GitHub - hmnd/js-beautify: Beautifier for javascript
... To use js-beautify as a node library (after install locally), import and call the appropriate beautifier method for javascript (js), css, or html. All three method signatures are beautify(code, options).
Author   hmnd